当我在编译沙盒 c 程序后尝试运行 .out 文件时,出现以下错误:
./sandbox: error while loading shared libraries: libsandbox.so: cannot open shared object file: No such file or directory
我该怎么办?
当我在编译沙盒 c 程序后尝试运行 .out 文件时,出现以下错误:
./sandbox: error while loading shared libraries: libsandbox.so: cannot open shared object file: No such file or directory
我该怎么办?
“共享库丢失”问题并非libsandbox
. 许多使用 GNU 自动工具进行构建配置的自编译库都会发生这种情况。
问题是 GNU autotools 会在默认情况下准备要使用的库/usr/local/lib
(并且有充分的理由让此设置保持默认状态,例如FHS一致性)。但是,在某些 Linux 发行版中——比如Ubuntu和ArchLinux——运行时链接器(aka. ld.so
)不会搜索共享/usr/local/lib
库,除非通过ldconfig
.
虽然@anton-kovalenko 的答案中的所有其他解决方案都是可行的,但如果您只配置libsandbox
选项--prefix=/usr
和--libdir=/usr/lib
(当然,如果您具有对 的写访问权限/usr/lib
)可能会更方便。或者您可以添加一个新ldconfig
条目/etc/ld.so.conf.d
以启用/usr/local/lib
系统级别的库搜索。
免责声明:我是libsandbox
.
您执行以下操作:
libsandbox.so
。如果您成功链接到它,它可能在某个地方。env LD_LIBRARY_PATH=/directory/of/your/libsandbox/copy/ ./sandbox
它是否有效。gcc -Wl,-rpath='$ORIGIN'
链接可以libsandbox.so
从可执行文件的目录加载。负责处理的包装脚本LD_LIBRARY_PATH
是另一种解决方案。放入libsandbox.so
动态链接器可以找到它的位置是另一个。