2

I’ve been trying to run this log4cplus sample on my PC:

http://log4cplus.sourceforge.net/loglevel.html

I’ve created my LogLevel project using VS2010 and I’m using log4cplus v1.1.0.

My program compiles fine but when I step this line

Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("main"));

I get the following error:

Unhandled exception at 0x75d5d3cf in LogLevel.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0030ed2c..

in "..\Microsoft Visual Studio 10.0\VC\crt\src\new.cpp" file (Line 63)

How can I get around this problem?

I'm aware there is another SO thread talking about the same issue but unfortunately it is unresolved.

Community
  • 1
  • 1
jpen
  • 2,129
  • 5
  • 32
  • 56
  • See my answer for the SO thread you linked to. It may help. – FishesCycle Nov 13 '12 at 23:41
  • @jpen: Are you using log4cplus as a static library? – wilx Dec 31 '12 at 07:34
  • @wilx - I just read your comment. Yes, I'm using it as a static library. – jpen Jan 11 '13 at 19:36
  • @jpen: Please fill a bug report at https://sourceforge.net/p/log4cplus/bugs/. Especially call stack information could be very helpful. I am not able to reproduce this but I think it might be because of order of construction of global and static variables. Is your `Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("main"));` line in file or namespace scope? Could you also please check out code out of trunk branch in Bazaar repository and test that? It contains changes that could fix this (initialization hooks that are run before threads or main() start). – wilx Jan 11 '13 at 19:57

1 Answers1

0

If you're building your application in debug, be sure to link to lib4CplusD.lib and lib4CplusD.dll. Likewise, a release application should link aginst lib4cplus.lib and lib4cplus.dll I had the same runtime error, and when I linked my debug application against the debug libraries, the problem was resolved.

Logger::getInstance causing bad_alloc exception in log4cplus

Community
  • 1
  • 1
lbf
  • 1