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 Meongchul Song <mc...@yahoo.com> on 2008/12/09 01:55:32 UTC

Link error when using Layout on MS Windows

Hello, 

I am experiencing a link error when I am trying to add a new logger on the fly.
The code snippet is shown below and it works fine on Linux. 
But running on MS Windows causes a link error.
When I commented out two lines indicated by ===>, I don't see any link error.
Changing the PatternLayoutPtr to SimpleLayoutPtr causes similar problem too.

I am using log4cxx 0.10.0 with Visual Studio 2005.

Thank you the help in advance.

Regards, 

M. Song


 log4cxx::LoggerPtr tmpLogger( log4cxx::Logger::getLogger("SIM.TEST") );
 // set logger level
 tmpLogger->setLevel( log4cxx::Level::getDebug() );

             // set appender properties
 ===>     log4cxx::PatternLayoutPtr layout( new log4cxx::PatternLayout( "%d %-5p [%l] [%c:%M] %m%n" ) );


  log4cxx::FileAppender *ap = new log4cxx::FileAppender;
===>  ap->setLayout ( layout );
  ap->setFile ( "test.log" );
  ap->setAppend ( true );
  tmpLogger->addAppender ( ap );




The error message is shown below:


Linking...
1>LoggingTest.obj : error LNK2019: unresolved external symbol "public: __thiscall log4cxx::PatternLayout::PatternLayout(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0PatternLayout@log4cxx@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "void __cdecl Example_04(void)" (?Example_04@@YAXXZ)
1>D:\Projects\build\logging\logging\Debug\logging.exe : fatal error LNK1120: 1 unresolved externals


      ________________________________________________________ 
180도 달라진 야후! 메일 - 알아서 척척! 새로운 야후! 메일은 10분에 한번 스스로 새 메시지를 받아온답니다.
http://kr.content.mail.yahoo.com/cgland

Re: Link error when using Layout on MS Windows

Posted by Meongchul Song <mc...@yahoo.com>.
Thank you for the valuable comments.

I found the cause of my problem.
I have been working on a  project that runs on both Linux and MS Windows.
Well, the default for logchar is wchar_t on MS Windows while UTF8 on Linux.
It's my fault that I did not double check the header file, log4cxx.h 

I modified log4cxx.h as follows and it is working fine now.

#ifdef WIN32
 #define LOG4CXX_LOGCHAR_IS_UNICHAR 0
 #define LOG4CXX_LOGCHAR_IS_UTF8 0
 #define LOG4CXX_LOGCHAR_IS_WCHAR 1
#else
 #define LOG4CXX_LOGCHAR_IS_UNICHAR 0
 #define LOG4CXX_LOGCHAR_IS_UTF8 1
 #define LOG4CXX_LOGCHAR_IS_WCHAR 0
#endif


Regards,

M. Song



----- 메시지 원본 ----
보낸 사람: peter.doornbosch <pe...@gmail.com>
받는 사람: Log4CXX User <lo...@logging.apache.org>
보낸 시간: 2008년 12월 11일 (목요일), 2:20:42 AM
제목: Re: Link error when using Layout on MS Windows

Hi,

> Anytime an argument takes a LogString or a logchar*, you should use LOG4CXX_STR() in the same manner you'd use _T() for TCHAR*.


That's valueable information.
Now that i know it, i see that it is mentioned in the FAQ. However, i didn't spot it there. I suggest the following question being added to the faq list:

Q: How can i convert a character literal into a LogString?
A: Use the LOG4CXX_STR() macro.

Regards
Peter


      ________________________________________________________ 
180도 달라진 야후! 메일 - 여러 개의 메시지를 동시에 확인? 새로운 야후! 메일의 탭으로 가능해집니다.
http://kr.content.mail.yahoo.com/cgland

Re: Link error when using Layout on MS Windows

Posted by "peter.doornbosch" <pe...@gmail.com>.
Hi,

> Anytime an argument takes a LogString or a logchar*, you should use  
> LOG4CXX_STR() in the same manner you'd use _T() for TCHAR*.


That's valueable information.
Now that i know it, i see that it is mentioned in the FAQ. However, i  
didn't spot it there. I suggest the following question being added to  
the faq list:

Q: How can i convert a character literal into a LogString?
A: Use the LOG4CXX_STR() macro.

Regards
Peter


Re: Link error when using Layout on MS Windows

Posted by Curt Arnold <ca...@apache.org>.
On Dec 9, 2008, at 2:44 PM, peter.doornbosch wrote:

> Hi,
>
>> log4cxx::LoggerPtr  
>> tmpLogger( log4cxx::Logger::getLogger("SIM.TEST") );
>> // set logger level
>> tmpLogger->setLevel( log4cxx::Level::getDebug() );
>>
>>             // set appender properties
>> ===>     log4cxx::PatternLayoutPtr layout( new  
>> log4cxx::PatternLayout( "%d %-5p [%l] [%c:%M] %m%n" ) );
>
> try this: new log4cxx::PatternLayout( L"%d %-5p [%l] [%c:%M] %m%n" )
> (yes, that is an "L" before the quotes ;-)
> or switch your project to unicode.
> => i think the problem is that the pattern is interpreted as being  
> of type char*, but the PatternLayout constructor expects unicode.
>
> hth
> peter
>

Use LOG4CXX_STR() which takes an ASCII literal and prepends the  
appropriate qualifier (L or nothing) depending on configuration.


>>     log4cxx::PatternLayoutPtr layout( new  
>> log4cxx::PatternLayout(LOG4CXX_STR( "%d %-5p [%l] [%c:%M] %m%n" )) );
>>

Anytime an argument takes a LogString or a logchar*, you should use  
LOG4CXX_STR() in the same manner you'd use _T() for TCHAR*.




Re: Link error when using Layout on MS Windows

Posted by "peter.doornbosch" <pe...@gmail.com>.
Hi,

>  log4cxx::LoggerPtr  
> tmpLogger( log4cxx::Logger::getLogger("SIM.TEST") );
>  // set logger level
>  tmpLogger->setLevel( log4cxx::Level::getDebug() );
>
>              // set appender properties
>  ===>     log4cxx::PatternLayoutPtr layout( new  
> log4cxx::PatternLayout( "%d %-5p [%l] [%c:%M] %m%n" ) );

try this: new log4cxx::PatternLayout( L"%d %-5p [%l] [%c:%M] %m%n" )
(yes, that is an "L" before the quotes ;-)
or switch your project to unicode.
=> i think the problem is that the pattern is interpreted as being of  
type char*, but the PatternLayout constructor expects unicode.

hth
peter


>
>
>
>   log4cxx::FileAppender *ap = new log4cxx::FileAppender;
> ===>  ap->setLayout ( layout );
>   ap->setFile ( "test.log" );
>   ap->setAppend ( true );
>   tmpLogger->addAppender ( ap );
>
>
>
>
> The error message is shown below:
>
>
> Linking...
> 1>LoggingTest.obj : error LNK2019: unresolved external symbol  
> "public: __thiscall log4cxx::PatternLayout::PatternLayout(class  
> std::basic_string<char,struct std::char_traits<char>,class  
> std::allocator<char> > const &)" (??0PatternLayout@log4cxx@@QAE@ABV? 
> $basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)  
> referenced in function "void __cdecl Example_04(void)" (? 
> Example_04@@YAXXZ)
> 1>D:\Projects\build\logging\logging\Debug\logging.exe : fatal error  
> LNK1120: 1 unresolved externals
>
>
>      ________________________________________________________
> 180도 달라진 야후! 메일 - 알아서 척척! 새로운 야후!  
> 메일은 10분에 한번 스스로 새 메시지를 받아온답니 
> 다.
> http://kr.content.mail.yahoo.com/cgland