如何编译同时使用windows.h和google glog(glog / logging.h)的c ++程序?

时间:2016-12-27 11:56:33

标签: c++ c windows visual-c++ glog

我有两个库A和B.库B是我自己的库,我需要“windows.h”。此外,对于某些功能,我需要使用第三方库A. A使用谷歌日志库,这是问题所在:

第一个错误是:

Severity Code Description Project File Line Error C1189 #error:  ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h

我在“A.h”之前定义了GLOG_NO_ABBREVIATED_SEVERITIES,但之后出现了奇怪的链接错误。我已经测试了所有建议的解决方案here,但没有一个可行。

在使用“windows.h”的项目中是否还有其他方法可以使用glog?

编辑:

链接器错误是:

 error LNK2019: unresolved external symbol "__declspec(dllimport) public: char __thiscall std::basic_ios<char,struct std::char_traits<char> >::fill(char)" (__imp_?fill@?$basic_ios@DU?$char_traits@D@std@@@std@@QAEDD@Z) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<char,struct std::char_traits<char>,char>(class std::basic_ostream<char,struct std::char_traits<char> > &,struct std::_Fillobj<char> const &)" (??$?6DU?$char_traits@D@std@@D@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@ABU?$_Fillobj@D@0@@Z)

 error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<(class std::ios_base & (__cdecl*)(class std::ios_base &))" (__imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@P6AAAVios_base@1@AAV21@@Z@Z) referenced in function _getHtsLables

 error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<(double)" (__imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@N@Z) referenced in function "public: virtual void __thiscall AD3::FactorDense::Print(class std::basic_ostream<char,struct std::char_traits<char> > &)" (?Print@FactorDense@AD3@@UAEXAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@@Z)

 fatal error LNK1120: 3 unresolved externals

2 个答案:

答案 0 :(得分:0)

添加GLOG_NO_ABBREVIATED_SEVERITIES后,我重新编译了A,但是没有任何变化。但是通过重新排序包含“ A.h”和“ windows.h”的内容解决了问题。当我在“ windows.h”之前包含“ A.h”时,没有错误出现!!!我不明白链接器错误的真正原因是什么! –付款人

答案 1 :(得分:0)

  1. 在包含 super.addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mouseEntered(java.awt.event.MouseEvent evt) { super.setIcon(imageIconHover); System.out.println("in"); } @Override public void mouseExited(java.awt.event.MouseEvent evt) { super.setIcon(imageIcon); System.out.println("out"); } }); 之前定义GLOG_NO_ABBREVIATED_SEVERITIES

    logging.h
  2. 在Visual Studio的预处理器定义中添加 #define GLOG_NO_ABBREVIATED_SEVERITIES #include <windows.h> #include <glog/logging.h> ,即GLOG_NO_ABBREVIATED_SEVERITIES