Wednesday, April 16, 2014

How to build log4cpp 1.0 using Visual Studio

Attempt to compile log4cpp with more modern release of Visual Studio, than VS 6.0, will fail with error:

Appender.sbr No such file or directory

To solve the issue open properties of file NTEventLogCategories.mc in Visual Studio, find General settings of Custom Build Steps. Check Command Line. There are wrong paths to the utilities mc.exe, rc.exe and link.exe. Fix them and compilation will success.

Compilation in Visual Studio 2012 can produce an error:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdint.h(11): error C2632: '__int64' followed by '__int64' is illegal

To fix it edit file config-win32.h. Find and comment the following line:
#define int64_t __int64

Compiling DLL or linking static library with you project can produce liner errors like this:

5>log4cpp.lib(NTEventLogAppender.obj) : error LNK2001: unresolved external symbol "public: class std::_Tree_const_iterator,class std::allocator > const ,class std::basic_string,class std::allocator > > > > > __thiscall log4cpp::FactoryParams::find(class std::basic_string,class std::allocator > const &)const " (?find@FactoryParams@log4cpp@@QBE?AV?$_Tree_const_iterator@V?$_Tree_val@U?$_Tree_simple_types@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@std@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@4@@Z)
5>log4cpp.lib(RemoteSyslogAppender.obj) : error LNK2001: unresolved external symbol "public: class std::_Tree_const_iterator,class std::allocator > const ,class std::basic_string,class std::allocator > > > > > __thiscall log4cpp::FactoryParams::find(class std::basic_string,class std::allocator > const &)const " (?find@FactoryParams@log4cpp@@QBE?AV?$_Tree_const_iterator@V?$_Tree_val@U?$_Tree_simple_types@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@std@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@4@@Z)
5>log4cpp.lib(PatternLayout.obj) : error LNK2001: unresolved external symbol "public: class std::_Tree_const_iterator,class std::allocator > const ,class std::basic_string,class std::allocator > > > > > __thiscall log4cpp::FactoryParams::find(class std::basic_string,class std::allocator > const &)const " (?find@FactoryParams@log4cpp@@QBE?AV?$_Tree_const_iterator@V?$_Tree_val@U?$_Tree_simple_types@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@std@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@4@@Z)
5>log4cpp.lib(FileAppender.obj) : error LNK2001: unresolved external symbol "public: class std::_Tree_const_iterator,class std::allocator > const ,class std::basic_string,class std::allocator > > > > > __thiscall log4cpp::FactoryParams::find(class std::basic_string,class std::allocator > const &)const " (?find@FactoryParams@log4cpp@@QBE?AV?$_Tree_const_iterator@V?$_Tree_val@U?$_Tree_simple_types@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@std@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@4@@Z)
5>log4cpp.lib(RollingFileAppender.obj) : error LNK2001: unresolved external symbol "public: class std::_Tree_const_iterator,class std::allocator > const ,class std::basic_string,class std::allocator > > > > > __thiscall log4cpp::FactoryParams::find(class std::basic_string,class std::allocator > const &)const " (?find@FactoryParams@log4cpp@@QBE?AV?$_Tree_const_iterator@V?$_Tree_val@U?$_Tree_simple_types@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@std@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@4@@Z)
5>log4cpp.lib(AbortAppender.obj) : error LNK2001: unresolved external symbol "public: class std::_Tree_const_iterator,class std::allocator > const ,class std::basic_string,class std::allocator > > > > > __thiscall log4cpp::FactoryParams::find(class std::basic_string,class std::allocator > const &)const " (?find@FactoryParams@log4cpp@@QBE?AV?$_Tree_const_iterator@V?$_Tree_val@U?$_Tree_simple_types@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@std@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@4@@Z)
5>log4cpp.lib(Win32DebugAppender.obj) : error LNK2001: unresolved external symbol "public: class std::_Tree_const_iterator,class std::allocator > const ,class std::basic_string,class std::allocator > > > > > __thiscall log4cpp::FactoryParams::find(class std::basic_string,class std::allocator > const &)const " (?find@FactoryParams@log4cpp@@QBE?AV?$_Tree_const_iterator@V?$_Tree_val@U?$_Tree_simple_types@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@std@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@4@@Z)
5>log4cpp.lib(PatternLayout.obj) : error LNK2001: unresolved external symbol "void __cdecl log4cpp::localtime(__int64 const *,struct tm *)" (?localtime@log4cpp@@YAXPB_JPAUtm@@@Z)

Check log4cpp project and you will see not all cpp files are included. You need to add at least these files to success:

src/Localtime.cpp
src/FactoryParams.cpp

PS: log4cpp 1.1 have ready to use project files for modern compilers

No comments: