cannot open shared object file: No such file or directory
2017-10-26 17:04
453 查看
一. 前言
c语言编程, 希望调用动态链接库, 即 libxxx.so 文件, 编译好之后, 运行失败, 爆出如下错误:# ./test: error while loading shared libraries: libxxx.so: cannot open shared object file: No such file or directory
二. 故障原因
由于系统找不到这个libxxx.so 文件, 所以爆出这个错误三. 解决方案[1]
1) 如果共享库文件安装到了/lib或/usr/lib目录下, 那么需执行一下ldconfig命令2)
如果共享库文件安装到了/usr/local/lib(很多开源的共享库都会安装到该目录下)或其它"非/lib或/usr/lib"目录下, 那么在执行ldconfig命令前, 还要把新共享库目录加入到共享库配置文件/etc/ld.so.conf中, 如下:
# cat
/etc/ld.so.conf
include ld.so.conf.d/*.conf
# echo
"/usr/local/lib" >> /etc/ld.so.conf
# ldconfig
3)
如果共享库文件安装到了其它"非/lib或/usr/lib" 目录下, 但是又不想在/etc/ld.so.conf中加路径(或者是没有权限加路径). 那可以export一个全局变量LD_LIBRARY_PATH, 然后运行程序的时候就会去这个目录中找共享库.
LD_LIBRARY_PATH的意思是告诉loader在哪些目录中可以找到共享库. 可以设置多个搜索目录, 这些目录之间用冒号分隔开. 比如安装了一个mysql到/usr/local/mysql目录下, 其中有一大堆库文件在/usr/local/mysql/lib下面, 则可以在.bashrc或.bash_profile或shell里加入以下语句即可:
export LD_LIBRARY_PATH=/usr/local/mysql/lib:$LD_LIBRARY_PATH
一般来讲这只是一种临时的解决方案, 在没有权限或临时需要的时候使用.
参考文献
[1] http://blog.csdn.net/sahusoft/article/details/7388617
相关文章推荐
- ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory
- gm: error while loading shared libraries: libpng15.so.15: cannot open shared object file: No such file or directory
- OSError: libcudart.so.7.5: cannot open shared object file: No such file or directory
- 缺少动态连接库.so--cannot open shared object file: No such file or directory
- libcudart.so.6.5 cannot open shared object file: no such file or directory
- libpcre.so.1: cannot open shared object file: No such file or directory
- RAC srvctl 命令报 libpthread.so.0 cannot open shared object file No such file or directory 解决方法
- 问题ImportError: libcudnn.so.6: cannot open shared object file: No such file or directory的解决方案
- ImportError: libmysqlclient.so.20: cannot open shared object file: No such file or directory
- 【报错】ImportError: libcudnn.so.6: cannot open shared object file: No such file or directory
- caffe_.mexa64': libcaffe.so: cannot open shared object file: No such file or directory
- 彻底解决 libhdf5_hl.so.10: cannot open shared object file: No such file or directory
- 缺少动态连接库.so--cannot open shared object file: No such file or directory
- sybase iq 15.3 libXtst.so.6: cannot open shared object file: No such file or directory
- 错误:error libGL.so: cannot open shared object file: No such file or directory
- 缺少动态连接库.so--cannot open shared object file: No such file or directory
- ubuntu下tensorflow 报错 libcusolver.so.8.0: cannot open shared object file: No such file or directory
- android-sdks/build-tools/17.0.0/aapt: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
- 缺少动态连接库.so--cannot open shared object file: No such file or directory
- nginx排错error while loading shared libraries:libpcre.so.1:cannot open shared object file:No such file or directory