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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4581305/
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 00:03:52  来源:igfitidea点击:

error while loading shared libraries: libboost_system.so.1.45.0: cannot open shared object file: No such file or directory

c++linuxubuntuldldd

提问by skyeagle

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

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

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:

然后我在二进制文件上运行 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)

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?

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

采纳答案by peoro

The library cannot be found.

找不到库。

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

默认情况下,在 中查找库/lib/usr/lib并在/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.

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

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_PATHenvironment variable:

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

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.

我建议你使用你的包管理器安装 boost 库,无论如何,这会让你的生活更简单。

回答by ontek

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

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

回答by abo-abo

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:

我只是想为 Ubuntu(和 Debian,我猜)的用户添加一个注释:这些系统有一个安全“功能”,可以删除LD_LIBRARY_PATH. 这不起作用:

In either /etc/environemntor ~/.profileor ~/.bash_profile:

/etc/environemnt~/.profile或 中~/.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 makefrom e.g. emacsor eclipse, it won't work, unless you've launched emacsfrom the shell and not from the launcher.

它适用于~/.bashrc,但路径将仅为这个特定的交互式 shell 设置。这意味着,如果您make从 egemacs或调用eclipse,它将不起作用,除非您是emacs从 shell 而不是从启动器启动的。

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