我有以下不能编译的代码。
#include <stdio.h>
#include <log4cpp/Category.hh>
#include <log4cpp/FileAppender.hh>
#include <log4cpp/SimpleLayout.hh>
#define LOGFILE "./test.log"
int main()
{
/*Setting up Appender, layout and Category*/
log4cpp::Appender *appender = new log4cpp::FileAppender("FileAppender",LOGFILE);
log4cpp::Layout *layout = new log4cpp::SimpleLayout();
log4cpp::Category& category = log4cpp::Category::getInstance("Category");
appender->setLayout(layout);
category.setAppender(appender);
category.setPriority(log4cpp::Priority::INFO);
/*The actual logging*/
category.info("This is for tracing the flow");
category.notice("This is to notify certain events");
category.warn("This is to generate certain warnings");
}$ g++ -I/usr/local/include/log4cpp -L/usr/local/lib/ -llog4cpp -lpthread log.cc
这段代码会编译。但是我得到了下面的错误。
./a.out: error while loading shared libraries: liblog4cpp.so.4: cannot open shared object file: No such file or directory我确实在/usr/local/lib文件夹中看到了liblog4cpp.so.4。我该如何解决这个问题?
发布于 2011-11-18 03:20:59
如果是从非标准位置链接,加载器将找不到库。您有几个选项:
根据具体情况进行通知:将路径添加到可执行文件中:使用环境向链接器command.
export LD_LIBRARY_PATH).(我想
-Wl,-r,/usr/local/lib就行了(一个合适的构建环境(比如cmake)通常会自动添加(2)中的链接器选项,如果您让它将库定位在非标准位置。)
如果您有加载问题,请始终检查ldd ./a.out,以检查缺少哪些库。
发布于 2014-11-06 23:35:46
我在另一个程序中也遇到了类似的错误。
但是将这一行添加到主目录中的.bashrc文件就解决了这个问题。(激活并在重新记录过程中持续存在)
export LD_LIBRARY_PATH=path/to/log4cpp/lib:$LD_LIBRARY_PATHhttps://stackoverflow.com/questions/8172883
复制相似问题