已编译 C++程序引发“无法打开共享对象文件”在另一个系统上,尽管该文件存在

发布于 2024-09-30 17:45:37 字数 394 浏览 8 评论 0原文

我编写了一个小程序,需要一些库,包括 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

黎歌 2024-10-07 17:45:37

首先,尝试发出 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...

神经大条 2024-10-07 17:45:37

看起来您需要静态链接该库。这是一个很好的解释。 增强静态链接

Looks like you need to statically link the library. Here's a good explanation. Boost static linking

烟酉 2024-10-07 17:45:37

您是否链接到同一版本的 boost_filesystem 库?根据您编译应用程序的方式,它需要存在完全相同的库版本。

您可以尝试检查您的应用程序实际寻找的内容:

ldd <your app name>

可能还检查您的 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:

ldd <your app name>

Probably check your LD_LIBRARY_PATH environment variable as well.

一紙繁鸢 2024-10-07 17:45:37

您能否确保 /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 ?

琴流音 2024-10-07 17:45:37

您是否编译了 boost 的共享二进制文件并将其提供给用户?

通常可以使用 boost 而无需提供任何二进制/共享。但是,如果您使用 boost::filesystem,则必须将二进制文件构建为 lib 或共享对象,并确保它可用于最终的可执行共享二进制搜索路径。

您可以在 boost 文档中找到解释和更多详细信息。这是Linux版本: http://www.boost .org/doc/libs/1_44_0/more/getting_started/unix-variants.html

从此页面:

大多数 Boost 库仅包含头文件:
它们完全由头文件组成
包含模板和内联
功能,并且不需要
单独编译的库二进制文件
或链接时的特殊处理。

...

唯一必须的 Boost 库
单独构建的是:

  • Boost.文件系统
  • Boost.GraphParallel
  • Boost.IOStreams
  • Boost.MPI
  • Boost.ProgramOptions
  • Boost.Python(参见
    Boost.Python 构建文档
    在构建和安装之前)
  • Boost.Regex
  • Boost.序列化
  • Boost.Signals
  • Boost.System
  • Boost.Thread
  • Boost.Wave

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 :

Most Boost libraries are header-only:
they consist entirely of header files
containing templates and inline
functions, and require no
separately-compiled library binaries
or special treatment when linking.

...

The only Boost libraries that must be
built separately are:

  • Boost.Filesystem
  • Boost.GraphParallel
  • Boost.IOStreams
  • Boost.MPI
  • Boost.ProgramOptions
  • Boost.Python (see
    the Boost.Python build documentation
    before building and installing it)
  • Boost.Regex
  • Boost.Serialization
  • Boost.Signals
  • Boost.System
  • Boost.Thread
  • Boost.Wave
站稳脚跟 2024-10-07 17:45:37

/usr/lib 在你的 LD_LIBRARY_PATH 环境变量中吗?

is /usr/lib in your LD_LIBRARY_PATH environment variable?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文