I used vs2005 to build an static library of log4cplus-1.1.1-rc(2,3) with /MT configuration. When I run unit test program, it always shows:
runtime error R6030 - CRT not initialized
But this error doesn't show when I use log4cplus-1.1.1-rc1 with /MT.
I did some diff to find the problem. The root cause is log4cplus used TLS callback since rc2 (global-init.cxx). And it seems to not support well when build with /MT.
I found a related web page for this:
http://stackoverflow.com/questions/14538159/about-tls-callback-in-windows
BTW, use vs2012 to build with /MT also has another crash problem, the callstack shows:
....REPEAT ntdll.dll!_KiUserExceptionDispatcher@8() Unknown bb40e64e() Unknown appender_test.exe!__crtFlsGetValue(unsigned long dwFlsIndex) Line 394 C appender_test.exe!_getptd_noexit() Line 277 C appender_test.exe!_getptd() Line 337 C appender_test.exe!__InternalCxxFrameHandler(EHExceptionRecord * pExcept, EHRegistrationNode * pRN, _CONTEXT * pContext, void * pDC, const _s_FuncInfo * pFuncInfo, int CatchDepth, EHRegistrationNode * pMarkerRN, unsigned char recursive) Line 337 C++ appender_test.exe!__CxxFrameHandler3(EHExceptionRecord * pExcept, EHRegistrationNode * pRN, void * pContext, void * pDC) Line 355 C++ ntdll.dll!ExecuteHandler2@20() Unknown ntdll.dll!ExecuteHandler@20() Unknown ntdll.dll!_RtlDispatchException@8() Unknown ntdll.dll!_KiUserExceptionDispatcher@8() Unknown bb40e64e() Unknown appender_test.exe!__crtFlsGetValue(unsigned long dwFlsIndex) Line 394 C appender_test.exe!_getptd_noexit() Line 277 C appender_test.exe!_getptd() Line 337 C appender_test.exe!__InternalCxxFrameHandler(EHExceptionRecord * pExcept, EHRegistrationNode * pRN, _CONTEXT * pContext, void * pDC, const _s_FuncInfo * pFuncInfo, int CatchDepth, EHRegistrationNode * pMarkerRN, unsigned char recursive) Line 337 C++ appender_test.exe!__CxxFrameHandler3(EHExceptionRecord * pExcept, EHRegistrationNode * pRN, void * pContext, void * pDC) Line 355 C++ ntdll.dll!ExecuteHandler2@20() Unknown ntdll.dll!ExecuteHandler@20() Unknown ntdll.dll!_RtlDispatchException@8() Unknown
I am not familiar with TLS callback, but I think it should not be used with library is not a DLL.
TBH, I am inclined to mark this as 'not a bug' or 'won't fix' because /MT or /MTd is not one of supported configurations. It is either that or forcing everybody to initialize log4cplus in
main()
throughlog4cplus::initializeLog4cplus()
.Let me think about it a little bit more, though.
I have committed a change to both trunk and 1.1.x branch that makes log4cplus complain loudly during compilation if you do not use DLL C run time library. I do not think there is any other better way to do this.
Diff: