logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hale, Elaine" <Elaine_H...@nrel.gov>
Subject MS Visual Studio 2008 LNK2005 and LNK4006 errors and warnings that seem to be associated with log4cxx
Date Wed, 10 Dec 2008 02:51:56 GMT
Hello,

 

I was writing and running some tests for a project that uses log4cxx and
some other third party libraries, and received the following linking
errors upon adding the line 

 

::std::deque<::std::string> textSnippets;

 

to my testing header file (the errors go away if I comment it out):

 

4>Linking...

4>LINK :
C:\projects\pathfinders\cpp\utilities\projects\lib\Debug\ApplicationUtil
ities_Tests.exe not found or not built by the last incremental link;
performing full link

4>ApplicationUtilities.lib(log4cxx.dll) : error LNK2005: "public: void
__thiscall std::allocator<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > >::destroy(class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > *)"
(?destroy@?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocato
r@D@2@@std@@@std@@QAEXPAV?$basic_string@DU?$char_traits@D@std@@V?$alloca
tor@D@2@@2@@Z) already defined in ApplicationUtilities_Tests.obj

4>ApplicationUtilities.lib(log4cxx.dll) : error LNK2005: "protected:
__thiscall std::_Container_base_aux_alloc_empty<class
std::allocator<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > >
>::~_Container_base_aux_alloc_empty<class std::allocator<class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > > >(void)"
(??1?$_Container_base_aux_alloc_empty@V?$allocator@V?$basic_string@DU?$c
har_traits@D@std@@V?$allocator@D@2@@std@@@std@@@std@@IAE@XZ) already
defined in ApplicationUtilities_Tests.obj

4>ApplicationUtilities.lib(log4cxx.dll) : error LNK2005: "public: void
__thiscall std::allocator<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > >::deallocate(class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > *,unsigned int)"
(?deallocate@?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$alloc
ator@D@2@@std@@@std@@QAEXPAV?$basic_string@DU?$char_traits@D@std@@V?$all
ocator@D@2@@2@I@Z) already defined in ApplicationUtilities_Tests.obj

4>C:\projects\pathfinders\cpp\utilities\projects\lib\Debug\ApplicationUt
ilities_Tests.exe : fatal error LNK1169: one or more multiply defined
symbols found

 

General online help concerning LNK2005 errors associated with the
standard template library suggests checking that all of the runtime
libraries (under Properties->C++->Code Generation) in all dependencies
are identical.  So I did that, and they all seem to be set identically
to Multi-threaded Debug DLL (/MDd) (in the debug versions).  That
includes my log4cxx and other third-party builds.

 

I therefore tried to isolate the problem by creating a small project
that reproduces the errors.  I didn't quite succeed, but I did get the
following warnings, which seem very similar to the LNK2005 errors above,
from a simple library that uses log4cxx.lib and deque<string>:

 

1>------ Rebuild All started: Project: StdLibLinkingBug, Configuration:
Debug Win32 ------

1>Deleting intermediate and output files for project 'StdLibLinkingBug',
configuration 'Debug|Win32'

1>Compiling...

1>StdLibLinkingBug.cpp

1>Creating library...

1>StdLibLinkingBug.obj : warning LNK4006: "protected: __thiscall
std::_Container_base_aux_alloc_empty<class std::allocator<class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > > >::~_Container_base_aux_alloc_empty<class
std::allocator<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > > >(void)"
(??1?$_Container_base_aux_alloc_empty@V?$allocator@V?$basic_string@DU?$c
har_traits@D@std@@V?$allocator@D@2@@std@@@std@@@std@@IAE@XZ) already
defined in log4cxx.lib(log4cxx.dll); second definition ignored

1>StdLibLinkingBug.obj : warning LNK4006: "public: void __thiscall
std::allocator<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > >::deallocate(class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > *,unsigned int)"
(?deallocate@?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$alloc
ator@D@2@@std@@@std@@QAEXPAV?$basic_string@DU?$char_traits@D@std@@V?$all
ocator@D@2@@2@I@Z) already defined in log4cxx.lib(log4cxx.dll); second
definition ignored

1>StdLibLinkingBug.obj : warning LNK4006: "public: void __thiscall
std::allocator<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > >::destroy(class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > *)"
(?destroy@?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocato
r@D@2@@std@@@std@@QAEXPAV?$basic_string@DU?$char_traits@D@std@@V?$alloca
tor@D@2@@2@@Z) already defined in log4cxx.lib(log4cxx.dll); second
definition ignored

1>Build log was saved at
"file://c:\projects\pathfinders\cpp\utilities\projects\debugging\StdLibL
inkingBug\Debug\BuildLog.htm"

1>StdLibLinkingBug - 0 error(s), 3 warning(s)

========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

 

Since writing similar small programs with the other third party
libraries I'm using did not produce anything similar to the LNK2005
errors, I am guessing that log4cxx is the culprit.

 

Other (possibly) useful information:

-          the warnings and errors do not go away if I replace
deque<string> with vector<string>, but they do go away if I replace
deque<string> with deque<int>

-          the original problem cropped up in a series of dependent
static library projects that were finally linked into a .exe.  Basically
the situation is something like (where x -> y means y uses or is
dependent on x):

log4cxx -> lib1 (log4cxx wrapper for outputing log messages) -> lib2 ->
lib3 (which declares a deque<string> and configures log4cxx loggers);
lib2 and lib3 -> exe (which gives linking errors when it declares a
deque<string>)

-          the code for the small library that produced the LNK4006
warnings follows.  The .vsproj file lists log4cxx as a dependency.  The
warnings go away if this listing is removed.

 

// StdLibLinkingBug.h

 

#include <deque>

#include <string>

 

#ifndef STDLIBLINKINGBUG_H

#define STDLIBLINKINGBUG_H

 

void functionThatLogs(std::deque<std::string>);

 

#endif // STDLIBLINKINGBUG_H

 

// StdLibLinkingBug.cpp

 

#include "StdLibLinkingBug.h"

#include <log4cxx/logger.h>

 

using namespace std;

using namespace log4cxx;

 

LoggerPtr logger(Logger::getLogger("StdLibLinkingBug"));

 

void functionThatLogs(std::deque<std::string> aStringDeque)

{

  LOG4CXX_WARN(logger,"A silly message " << aStringDeque.at(0))

}

 

Any help anyone can provide would be greatly appreciated.  This bug has
me stumped!

 

Thanks,

Elaine

 

Elaine T. Hale, Ph.D.

Buildings and Thermal Systems Center

National Renewable Energy Laboratory

 

elaine_hale@nrel.gov

303-384-7812

MS 4111


Mime
View raw message