加载共享库时出错:libboost_system.so.1.45.0:无法打开共享对象文件:没有这样的文件或目录

发布于 2024-10-10 05:23:53 字数 974 浏览 11 评论 0原文

我正在 Linux 上构建 C++ 可执行文件。可执行文件链接到一些 boost 库。

这是我尝试运行二进制文件时的输出:

root@yourbox:~/work/dev/c++/projects/testfgci/dist/Debug/GNU-Linux-x86$ ./testfgci 
./testfgci: error while loading shared libraries: libboost_system.so.1.45.0: cannot open shared object file: No such file or directory

然后我在二进制文件上运行 ldd 以检查依赖关系:

root@yourbox:~/work/dev/c++/projects/testfgci/dist/Debug/GNU-Linux-x86$ ldd testfgci 
    linux-gate.so.1 =>  (0x00380000)
    libboost_system.so.1.45.0 => not found
    libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00b50000)
    libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0x005f6000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x0099a000)
    libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x001b3000)
    libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0x00110000)
    /lib/ld-linux.so.2 (0x00ea2000)

我不确定为什么找不到 liboos_system.sl.1.45.0 SO。我今天早些时候成功构建了它。谁能解释一下吗?

I am building a C++ executable on Linux. The executable links into some boost libraries.

This is the output when I attempt to run the binary:

root@yourbox:~/work/dev/c++/projects/testfgci/dist/Debug/GNU-Linux-x86$ ./testfgci 
./testfgci: error while loading shared libraries: libboost_system.so.1.45.0: cannot open shared object file: No such file or directory

I then run ldd on the binary to check dependencies:

root@yourbox:~/work/dev/c++/projects/testfgci/dist/Debug/GNU-Linux-x86$ ldd testfgci 
    linux-gate.so.1 =>  (0x00380000)
    libboost_system.so.1.45.0 => not found
    libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00b50000)
    libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0x005f6000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x0099a000)
    libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x001b3000)
    libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0x00110000)
    /lib/ld-linux.so.2 (0x00ea2000)

I am not sure why the liboos_system.sl.1.45.0 SO is not found. I built it successfully a little earlier on today. Can anyone explain?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

云雾 2024-10-17 05:23:53

找不到该库。

默认情况下,在 /lib/usr/lib 以及 /etc/ld.so.conf 指定的目录中查找库。

通常系统库(例如 boost,如果您通过包管理器安装了它)位于 /usr/lib 中,但这可能不是您的情况。

您的 boost 库位于系统上的什么位置?是你自己编译的吗?在这种情况下,您应该告诉动态链接器使用 LD_LIBRARY_PATH 环境变量在它们所在的目录中查找您的库:

LD_LIBRARY_PATH="your/boost/directory" ./testfgci

无论如何,我建议您使用包管理器安装 boost 库,这将使您的生活变得更加简单。

The library cannot be found.

Libraries are by default looked for in /lib, /usr/lib and the directories specified by /etc/ld.so.conf.

Usually system libraries (like boost, if you installed it via your package manager) are located in /usr/lib, but it's probably not your case.

Where are your boost libraries located on your system? Did you compile them by yourself? In this case you should tell the dynamic linker to look for your libraries in the directory they're located by using the LD_LIBRARY_PATH environment variable:

LD_LIBRARY_PATH="your/boost/directory" ./testfgci

I'd suggest you to install boost libraries using your package manager, anyway, this will make your life a lot simpler.

漫漫岁月 2024-10-17 05:23:53

我知道这是旧的,但您可以运行 ldconfig 来重建 ld 缓存。这样您就不需要更新LD_LIBRARY_PATH

I know that this is an old one, but you can run ldconfig to rebuild your ld cache. That way you don't need to update LD_LIBRARY_PATH.

叹倦 2024-10-17 05:23:53

我只是想为 Ubuntu(我猜还有 Debian)的用户添加一条注释:
这些系统具有擦除LD_LIBRARY_PATH的安全“功能”。
这不起作用:

/etc/environemnt~/.profile~/.bash_profile 中:

export LD_LIBRARY_PATH=/usr/local/boost_1_54_0/stage/lib:$LD_LIBRARY_PATH

它将适用于 ~/.bashrc,但路径将仅为此特定设置
交互式外壳。这意味着如果您从 emacseclipse 调用 make
除非您从 shell 而不是从启动器启动 emacs ,否则它将无法工作。

这对我有用:

echo -e "\n/usr/local/boost_1_54_0/stage/lib" | sudo tee -a /etc/ld.so.conf 
sudo ldconfig

I just wanted to add a note for users of Ubuntu (and Debian, I guess):
these systems have a security "feature" that erases LD_LIBRARY_PATH.
This doesn't work:

In either /etc/environemnt or ~/.profile or ~/.bash_profile:

export LD_LIBRARY_PATH=/usr/local/boost_1_54_0/stage/lib:$LD_LIBRARY_PATH

It will work for ~/.bashrc, but the path will be set just for this particular
interactive shell. This means that if you invoke make from e.g. emacs or eclipse,
it won't work, unless you've launched emacs from the shell and not from the launcher.

This is what worked for me:

echo -e "\n/usr/local/boost_1_54_0/stage/lib" | sudo tee -a /etc/ld.so.conf 
sudo ldconfig
妄司 2024-10-17 05:23:53

正如 peoro他的回答中提到的,使用包管理器安装它。例如,如果您使用的是 Ubuntu 18.04,请运行

sudo apt install libboost-filesystem1.65.1

As peoro mentioned in his answer, install it using a package manager. E.g., if you are using Ubuntu 18.04, run

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