0

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
payman
  • 300
  • 2
  • 15
  • You may have more than just one problem here. The "ERROR macro is defines" seems to be fixed by following the advise in the #error message: "Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h" (that is NOT before your #include "A.h", as you did, but seems to work somehow. The linker error may be caused by not linking to some required library. I suggest you to edit your question and add the linker error. – roalz Dec 27 '16 at 12:06
  • 1
    Separate the use of A and B to two compilation units, so that you don't need to include both in one compilation unit, hence avoid the conflict? – user3528438 Dec 27 '16 at 12:13
  • @roalz : I don't think so, the linker errors appears even if I don't use any functions from "A" library in my code and just include "A.h". Anyway, I have added linker errors to my question. But they are confusing!!! – payman Dec 27 '16 at 12:30
  • 1
    They are not confusing, but trying to understand what you have done without seeing a minimal, compilable source code example that shows your problem can be very difficult. I see you are using Microsoft Visual C++ compiler (which version?). One of the reasons for those linker errors may be mismatching compiler settings for libraries and program (i.e. some are debug, other not) when exporting C++ symbols. – roalz Dec 27 '16 at 12:37
  • @user3528438 : Can you please explain your solution? I have to use A's exported functions in B's functions. Is it possible to separate them? – payman Dec 27 '16 at 12:40
  • @roalz : I am using visual c++ 2015, and I have checked compiler options in project->properties->c++->codeGeneration and linker->advanced and they are same, is there any other compiler options to be checked? – payman Dec 27 '16 at 12:49
  • 1
    It's possible as long as you don't call A's function and `windows.h`'s function in the same B's function, and B's header does not depend on both A's header and `windows.h`. – user3528438 Dec 27 '16 at 13:00
  • 1
    To answer your other question, you probably need to recompile A after you add `GLOG_NO_ABBREVIATED_SEVERITIES` – user3528438 Dec 27 '16 at 13:01
  • 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 Dec 27 '16 at 13:26

2 Answers2

1
  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.

Ralf
  • 16,086
  • 4
  • 44
  • 68
sachinsaini
  • 53
  • 1
  • 10
0

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

Armali
  • 18,255
  • 14
  • 57
  • 171