加载共享库时出错:libboost_system.so.1.45.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
找不到该库。
默认情况下,在
/lib
、/usr/lib
以及/etc/ld.so.conf
指定的目录中查找库。通常系统库(例如 boost,如果您通过包管理器安装了它)位于
/usr/lib
中,但这可能不是您的情况。您的 boost 库位于系统上的什么位置?是你自己编译的吗?在这种情况下,您应该告诉动态链接器使用 LD_LIBRARY_PATH 环境变量在它们所在的目录中查找您的库:
无论如何,我建议您使用包管理器安装 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:I'd suggest you to install boost libraries using your package manager, anyway, this will make your life a lot simpler.
我知道这是旧的,但您可以运行 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 updateLD_LIBRARY_PATH
.我只是想为 Ubuntu(我猜还有 Debian)的用户添加一条注释:
这些系统具有擦除
LD_LIBRARY_PATH
的安全“功能”。这不起作用:
在
/etc/environemnt
或~/.profile
或~/.bash_profile
中:它将适用于
~/.bashrc
,但路径将仅为此特定设置交互式外壳。这意味着如果您从
emacs
或eclipse
调用make
,除非您从 shell 而不是从启动器启动
emacs
,否则它将无法工作。这对我有用:
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
:It will work for
~/.bashrc
, but the path will be set just for this particularinteractive shell. This means that if you invoke
make
from e.g.emacs
oreclipse
,it won't work, unless you've launched
emacs
from the shell and not from the launcher.This is what worked for me:
正如 peoro 在他的回答中提到的,使用包管理器安装它。例如,如果您使用的是 Ubuntu 18.04,请运行
As peoro mentioned in his answer, install it using a package manager. E.g., if you are using Ubuntu 18.04, run