已编译 C++程序引发“无法打开共享对象文件”在另一个系统上,尽管该文件存在
我编写了一个小程序,需要一些库,包括 libboost_filesystem、libboost_program_options 和 libcurl。
我在我的家用机器上编译了它,并将二进制文件带到我工作的计算机上进行测试。但是当我尝试启动该程序时,它会给出以下错误消息:
error while loading shared libraries:
libboost_filesystem.so.1.42.0: cannot
open shared object file
但是当我搜索该文件时,我发现它存在于: /usr/lib/libboost_filesystem.so.1.42.0
在编译/链接程序期间我是否出了问题?如果是的话我需要做什么才能让它在其他机器上工作?
I wrote a tiny program that requires some libraries including libboost_filesystem, libboost_program_options and libcurl.
I compiled it on my home machine and took the binary to my computer at work to test it there. But there it gives the following error message when I try to start the program:
error while loading shared libraries:
libboost_filesystem.so.1.42.0: cannot
open shared object file
But when I search for this file I see that it exists in:
/usr/lib/libboost_filesystem.so.1.42.0
Did I something wrong during the compilation / linking of my program? If yes what do I have to do to make it work on other machines?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
首先,尝试发出 ldconfig -p |在控制台中 grep libboost_filesystem.so 以确保该库位于您的 ld 缓存中。
如果不是,您可能需要将名为 boost.conf 的文件添加到 /etc/ld.so.conf.d 目录中。该文件应包含您的 boost 库的路径。然后运行 sudo ldconfig 来更新系统的 ld 缓存。
希望这会有所帮助...
First, try to issue
ldconfig -p | grep libboost_filesystem.so
in a console to make sure the library is in your ld cache.If it is not, you may need to add a file with a name like boost.conf to your /etc/ld.so.conf.d directory. This file should contain a path to your boost libraries. Then run
sudo ldconfig
to update your system's ld cache.Hope this will help...
看起来您需要静态链接该库。这是一个很好的解释。 增强静态链接
Looks like you need to statically link the library. Here's a good explanation. Boost static linking
您是否链接到同一版本的 boost_filesystem 库?根据您编译应用程序的方式,它需要存在完全相同的库版本。
您可以尝试检查您的应用程序实际寻找的内容:
可能还检查您的 LD_LIBRARY_PATH 环境变量。
Did you link against the same version of the boost_filesystem library? Depending on how you compile your application, it requires the very same version of the library to be present.
You could try to check for what your application actually looks for with:
Probably check your LD_LIBRARY_PATH environment variable as well.
您能否确保
/usr/lib/libboost_filesystem.so.1.42.0
不是死链接?Could you make sure that
/usr/lib/libboost_filesystem.so.1.42.0
is not a dead link ?您是否编译了 boost 的共享二进制文件并将其提供给用户?
通常可以使用 boost 而无需提供任何二进制/共享。但是,如果您使用 boost::filesystem,则必须将二进制文件构建为 lib 或共享对象,并确保它可用于最终的可执行共享二进制搜索路径。
您可以在 boost 文档中找到解释和更多详细信息。这是Linux版本: http://www.boost .org/doc/libs/1_44_0/more/getting_started/unix-variants.html
从此页面:
...
Did you compile the shared binaries of boost and provided them to the user?
Often boost can be used without any binary/shared to provide. But if you use, for example, boost::filesystem, you'll have to build the binaries, as lib or shared object, and make sure it's available to the final executable shared binary search path.
You can find an explaination and more details in the boost documentation. Here is the linux version : http://www.boost.org/doc/libs/1_44_0/more/getting_started/unix-variants.html
From this page :
...
/usr/lib 在你的 LD_LIBRARY_PATH 环境变量中吗?
is /usr/lib in your LD_LIBRARY_PATH environment variable?