You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-user@logging.apache.org by Gerrit van Doorn <gd...@newwireless.com> on 2009/05/29 19:09:54 UTC
linking errors when trying to use log4cxx as a static library (VC2008)
Hi,
I compiled log4cxx as a DLL before and it worked perfectly. Now I wanted
to use log4cxx (version 0.10.0) as a static library. I've set the
"Configuration Type" to "Static Library .lib" in the log4cxx properties
and I changed the Preprocessor -> Preprocessor definitions to
LOG4CXX_STATIC. When I compile in release mode I get a library file that
is about 14MB big. When I try to use this library in a simple program I
get the following linker errors:
1>Linking...
1>main.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) public: static class
log4cxx::helpers::ObjectPtrT<class log4cxx::Level> __cdecl
log4cxx::Level::getWarn(void)"
(__imp_?getWarn@Level@log4cxx@@SA?AV?$ObjectPtrT@VLevel@log4cxx@@@helpers@2@XZ)
1>main.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) public: class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > const & __thiscall
log4cxx::helpers::MessageBuffer::str(class
log4cxx::helpers::CharMessageBuffer &)"
(__imp_?str@MessageBuffer@helpers@log4cxx@@QAEABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAVCharMessageBuffer@23@@Z)
1>main.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) public: class log4cxx::helpers::CharMessageBuffer
& __thiscall log4cxx::helpers::MessageBuffer::operator<<(char const *)"
(__imp_??6MessageBuffer@helpers@log4cxx@@QAEAAVCharMessageBuffer@12@PBD@Z)
1>main.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) public: __thiscall
log4cxx::helpers::MessageBuffer::~MessageBuffer(void)"
(__imp_??1MessageBuffer@helpers@log4cxx@@QAE@XZ)
1>main.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) public: __thiscall
log4cxx::helpers::MessageBuffer::MessageBuffer(void)"
(__imp_??0MessageBuffer@helpers@log4cxx@@QAE@XZ)
1>main.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) public: bool __thiscall
log4cxx::Logger::isWarnEnabled(void)const "
(__imp_?isWarnEnabled@Logger@log4cxx@@QBE_NXZ)
1>main.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) public: static class
log4cxx::helpers::ObjectPtrT<class log4cxx::Logger> __cdecl
log4cxx::Logger::getLogger(char const * const)"
(__imp_?getLogger@Logger@log4cxx@@SA?AV?$ObjectPtrT@VLogger@log4cxx@@@helpers@2@QBD@Z)
1>main.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) public: void __thiscall
log4cxx::Logger::forcedLog(class log4cxx::helpers::ObjectPtrT<class
log4cxx::Level> const &,class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > const &,class
log4cxx::spi::LocationInfo const &)const "
(__imp_?forcedLog@Logger@log4cxx@@QBEXABV?$ObjectPtrT@VLevel@log4cxx@@@helpers@2@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABVLocationInfo@spi@2@@Z)
1>main.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) public: __thiscall
log4cxx::spi::LocationInfo::LocationInfo(char const * const,char const *
const,int)" (__imp_??0LocationInfo@spi@log4cxx@@QAE@QBD0H@Z)
1>main.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) public: class log4cxx::Logger * __thiscall
log4cxx::helpers::ObjectPtrT<class
log4cxx::Logger>::operator->(void)const "
(__imp_??C?$ObjectPtrT@VLogger@log4cxx@@@helpers@log4cxx@@QBEPAVLogger@2@XZ)
1>main.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) public: virtual __thiscall
log4cxx::helpers::ObjectPtrT<class log4cxx::Logger>::~ObjectPtrT<class
log4cxx::Logger>(void)"
(__imp_??1?$ObjectPtrT@VLogger@log4cxx@@@helpers@log4cxx@@UAE@XZ)
1>main.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) public: virtual __thiscall
log4cxx::helpers::ObjectPtrT<class log4cxx::Level>::~ObjectPtrT<class
log4cxx::Level>(void)"
(__imp_??1?$ObjectPtrT@VLevel@log4cxx@@@helpers@log4cxx@@UAE@XZ)
1>C:\Documents and Settings\gerrit\My Documents\Visual Studio
2008\Projects\log4cxxStaticTest\Release\log4cxxStaticTest.exe : fatal
error LNK1120: 12 unresolved externals
What am I doing wrong?
Here is the basic example:
#include <log4cxx/logger.h>
log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("myLogger"));
void main(void) {
LOG4CXX_WARN(logger, "Some warning");
}
- Gerrit
Re: linking errors when trying to use log4cxx as a static library
(VC2008)
Posted by Gerrit van Doorn <gd...@newwireless.com>.
Curt Arnold wrote:
>
> On May 29, 2009, at 12:09 PM, Gerrit van Doorn wrote:
>
>> Hi,
>>
>> I compiled log4cxx as a DLL before and it worked perfectly. Now I
>> wanted to use log4cxx (version 0.10.0) as a static library. I've set
>> the "Configuration Type" to "Static Library .lib" in the log4cxx
>> properties and I changed the Preprocessor -> Preprocessor definitions
>> to LOG4CXX_STATIC. When I compile in release mode I get a library
>> file that is about 14MB big. When I try to use this library in a
>> simple program I get the following linker errors:
>>
>> 1>Linking...
>> 1>main.obj : error LNK2001: unresolved external symbol
>> "__declspec(dllimport) public: static class
>> log4cxx::helpers::ObjectPtrT<class log4cxx::Level> __cdecl
>> log4cxx::Level::getWarn(void)"
>> (__imp_?getWarn@Level@log4cxx@@SA?AV?$ObjectPtrT@VLevel@log4cxx@@@helpers@2@XZ)
>>
>> 1>main.obj : error LNK2001: unresolved external symbol
>> "__declspec(dllimport) public: class std::basic_string<char,struct
>> std::char_traits<char>,class std::allocator<char> > const &
>> __thiscall log4cxx::helpers::MessageBuffer::str(class
>> log4cxx::helpers::CharMessageBuffer &)"
>> (__imp_?str@MessageBuffer@helpers@log4cxx@@QAEABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAVCharMessageBuffer@23@@Z)
>>
>
>> ...
>> What am I doing wrong?
>>
>> Here is the basic example:
>>
>> #include <log4cxx/logger.h>
>>
>> log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("myLogger"));
>>
>> void main(void) {
>> LOG4CXX_WARN(logger, "Some warning");
>> }
>>
>>
>> - Gerrit
>
>
> Notice that your link errors have __declspect(dllimport) which
> indicates that your calling code is still expecting to link with a
> log4cxx.dll. Likely, you did not define LOG4CXX_STATIC when you
> compiled your application.
>
I noticed that but didn't know why it does this. So I will need to
compile the log4cxx project using LOG4CXX_STATIC and i will also need to
define LOG4CXX_STATIC in my own project that links with the log4cxx.lib?
What is the regular size of the static library?
Re: linking errors when trying to use log4cxx as a static library (VC2008)
Posted by Curt Arnold <ca...@apache.org>.
On May 29, 2009, at 12:09 PM, Gerrit van Doorn wrote:
> Hi,
>
> I compiled log4cxx as a DLL before and it worked perfectly. Now I
> wanted to use log4cxx (version 0.10.0) as a static library. I've set
> the "Configuration Type" to "Static Library .lib" in the log4cxx
> properties and I changed the Preprocessor -> Preprocessor
> definitions to LOG4CXX_STATIC. When I compile in release mode I get
> a library file that is about 14MB big. When I try to use this
> library in a simple program I get the following linker errors:
>
> 1>Linking...
> 1>main.obj : error LNK2001: unresolved external symbol
> "__declspec(dllimport) public: static class
> log4cxx::helpers::ObjectPtrT<class log4cxx::Level> __cdecl
> log4cxx::Level::getWarn(void)" (__imp_?getWarn@Level@log4cxx@@SA?AV?
> $ObjectPtrT@VLevel@log4cxx@@@helpers@2@XZ)
> 1>main.obj : error LNK2001: unresolved external symbol
> "__declspec(dllimport) public: class std::basic_string<char,struct
> std::char_traits<char>,class std::allocator<char> > const &
> __thiscall log4cxx::helpers::MessageBuffer::str(class
> log4cxx::helpers::CharMessageBuffer &)" (__imp_?
> str@MessageBuffer@helpers@log4cxx@@QAEABV?$basic_string@DU?
> $char_traits@D@std@@V?$allocator@D@2@@std@@AAVCharMessageBuffer@23@@Z)
> ...
> What am I doing wrong?
>
> Here is the basic example:
>
> #include <log4cxx/logger.h>
>
> log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("myLogger"));
>
> void main(void) {
> LOG4CXX_WARN(logger, "Some warning");
> }
>
>
> - Gerrit
Notice that your link errors have __declspect(dllimport) which
indicates that your calling code is still expecting to link with a
log4cxx.dll. Likely, you did not define LOG4CXX_STATIC when you
compiled your application.