无法找到boost库。

4
这是一个非常基础的问题,我发帖只是因为我已经花了一些时间在上面。目前为止,以下是我所做的内容:
  1. Downloaded and compiled the boost library:

    sudo ./bootstrap.sh and sudo ./bjam install

    This way it was installed into /usr/local/lib.

  2. In my source code I've added only:

    #include <boost/asio.hpp>
    using boost::asio::ip::tcp
    
  3. I compile it with:

    g++ -I/usr/lib/jvm/java-6-openjdk/include -L/usr/local/lib -fPIC -lboost_system -shared -o libagent.so agent.cpp

  4. However, ldd -d ./libagent.so gives me:

    libboost_system.so.1.46.1 => not found

  5. But there is no error thrown, when using the -lboost_system and ls /usr/local/lib gets me among other things:

    libboost_system.so
    libboost_system.a

我漏掉了什么?


你运行了ldconfig吗?http://linux.die.net/man/8/ldconfig - PhilMY
2个回答

3
< p > ./bjam install 工具是否也运行了 ldconfig(8) 工具?ldconfig(8) 需要在安装新库后运行,以更新由 ld.so(8) 在程序执行时使用的缓存。


1
请运行以下命令(作为root用户):ldconfig -u - Alexandre C.
而 /usr/local/lib 应该在 ldconfig 的路径列表中。 - jopa
1
谢谢,运行sudo ldconfig -n /usr/local/lib解决了问题。 - Konrad Reiche

1

你应该使用以下方式进行编译:

g++ -I/usr/lib/jvm/java-6-openjdk/include -L/usr/local/lib -Wl,-rpath,/usr/local/lib -fPIC -lboost_system -shared -o libagent.so agent.cpp

这会使程序在运行时在 /usr/local/lib 中查找 boost 库,而 -L 选项只会在编译时在 /usr/local/lib 中查找。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接