How to compile a c++ program that uses both windows.h and google glog (glog/logging.h)?

3.5k Views Asked by At

I have two libraries A and B. Library B is my own library and I need "windows.h" in it. Also for some functions I need to use a third-party library A. A uses google logging library and here is the problem :

The first error was this :

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

I defined GLOG_NO_ABBREVIATED_SEVERITIES before "A.h", but after that strange linking errors appeared. I have tested all solutions suggested here but none of them works.

Is there any other ways to use glog in a project that uses "windows.h"?

EDIT :

The linker errors are :

 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

There are 2 best solutions below

0
On BEST ANSWER

I have recompiled A after adding GLOG_NO_ABBREVIATED_SEVERITIES, but nothing changed. But the problem solved by reordering the inclusion of "A.h" and "windows.h". When I include "A.h" before "windows.h" no error appears!!! I can not understand what was the real cause of linker errors! – payman

0
On
  1. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h

     #define GLOG_NO_ABBREVIATED_SEVERITIES
     #include <windows.h>
     #include <glog/logging.h>
    
  2. Add GLOG_NO_ABBREVIATED_SEVERITIES in preprocessor definitions in Visual Studio, i.e. Project > Properties > C/C++ > Preprocessor.