c++ - Logger::getInstance 在 log4cplus 中导致 bad_alloc 异常

标签 c++ windows runtime-error log4cplus

我正在尝试使用 log4cplus 在 C++ 应用程序中实现日志记录。我能够成功构建/链接(我将 log4cplus.lib 添加到我的附加库并将 log4cplus.dll 复制到构建/outdir)

当我运行我的应用程序时,当它执行我的 Logger::getInstance 调用时出现以下异常:

LogTesterConsole.exe 中 0x75cad36f 处的未处理异常:Microsoft C++ 异常:std::bad_alloc 位于内存位置 0x0013ed8c..

我试过将调用放在 main() 例程之外和内部,结果相同。

有什么想法吗?

代码:-

 #include "stdafx.h"
 #include <log4cplus/logger.h>
 #include <log4cplus/loggingmacros.h>
 #include <log4cplus/configurator.h>
 using namespace log4cplus;
 int _tmain(int argc, _TCHAR* argv[])
 { 
   BasicConfigurator config;
   config.configure();
   Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("main"));
   LOG4CPLUS_WARN(logger, LOG4CPLUS_TEXT("Hello, World!"));
   return 0;
 }

最佳答案

如果您在调试中构建应用程序,请确保链接到 lib4CplusD.lib 和 lib4CplusD.dll。同样,发布应用程序应该链接 aginst lib4cplus.lib 和 lib4cplus.dll 我遇到了同样的运行时错误,当我将调试应用程序链接到调试库时,问题就解决了。

关于c++ - Logger::getInstance 在 log4cplus 中导致 bad_alloc 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12230326/

相关文章:

c++ - 自动对比度和亮度(用于 OCR)

windows - 为 Web 应用程序创建 Windows 安装程序 (larragon/laravel)

windows - 我可以在一个窗口中有多个 Powershell 控制台吗?

c++ - CMake 无法链接 boost 库

java - 我正在尝试检查某些文件是否存在。为什么我的程序不允许用户输入文件?

machine-learning - Keras运行时错误: GpuCorrMM failed to allocate working memory of 576 x 802816

c++ - 如何绑定(bind) SOCI 查询的输出?

c++ - 为什么用 Eigen 和 OpenCV 计算的 SVD 左奇异 vector 有不同的符号

c++ - 如何为析构函数指定 nothrow 异常说明符?

google-apps-script - 类型错误 : Cannot read property "source" from undefined.(第 7 行,文件 "Code")