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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4078292/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 23:52:06  来源:igfitidea点击:

Compiled C++ program raises "cannot open shared object file" on another system though the file is present

c++linuxlinkerg++libraries

提问by tyrondis

I wrote a tiny program that requires some libraries including libboost_filesystem, libboost_program_options and libcurl.

我写了一个小程序,它需要一些库,包括 libboost_filesystem、libboost_program_options 和 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

但是当我搜索这个文件时,我看到它存在于:/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?

在我的程序编译/链接过程中我有什么问题吗?如果是,我需要做什么才能让它在其他机器上工作?

回答by Klaim

Did you compile the shared binaries of boost and provided them to the user?

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

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.

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

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

您可以在 boost 文档中找到解释和更多详细信息。这是 linux 版本: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.

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

...

...

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

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

  • Boost.Filesystem
  • Boost.GraphParallel
  • Boost.IOStreams
  • 增强型MPI
  • Boost.ProgramOptions
  • Boost.Python(在构建和安装之前请参阅 Boost.Python 构建文档)
  • Boost.Regex
  • Boost.Serialization
  • 升压信号
  • 升压系统
  • Boost.Thread
  • Boost.Wave

回答by prasanna

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

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

回答by Dominik Fretz

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.

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

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.

可能还要检查您的 LD_LIBRARY_PATH 环境变量。

回答by Antoine Pelisse

Could you make sure that /usr/lib/libboost_filesystem.so.1.42.0is not a dead link ?

你能确定那/usr/lib/libboost_filesystem.so.1.42.0不是死链接吗?

回答by ezpresso

First, try to issue ldconfig -p | grep libboost_filesystem.soin a console to make sure the library is in your ld cache.

首先,尝试ldconfig -p | grep libboost_filesystem.so在控制台中发出以确保库在您的 ld 缓存中。

If it is not, you may need to add a file with a name like boost.confto your /etc/ld.so.conf.ddirectory. This file should contain a path to your boost libraries. Then run sudo ldconfigto update your system's ld cache.

如果不是,您可能需要将名称类似于boost.conf的文件添加到您的/etc/ld.so.conf.d目录中。此文件应包含您的 boost 库的路径。然后运行sudo ldconfig以更新系统的 ld 缓存。

Hope this will help...

希望这会有所帮助...

回答by frankc

is /usr/lib in your LD_LIBRARY_PATH environment variable?

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