一、问题描述
运行程序时出现以下错误,原因是程序运行时需要的动态库找不到:
|
./app: error while loading shared libraries: libxxx.so: cannot open shared object file: No such file or directory |
解决方案有以下三种。
二、解决方案
2.1 方案 1
把需要的库文件复制到系统的默认库路径下:
系统默认的库文件有/lib
, /usr/lib
, /usr/local/lib
,64 位系统中的*/lib64
的也会有。
2.2 方案 2
把这个库的路径添加到/etc/ld.so.conf
文件中:
|
> sudo sh -c "pwd >> /etc/ld.so.conf" > sudo ldconfig |
2.3 方案 3
在环境变量中添加库文件地址:
|
> export LD_LIBRARY_PATH=$(pwd) |
三、测试
当前目录下有一个库文件 libfunc1.so
和一个依赖此文件的二进制程序 app
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
# 方案一 > ./app ./app: error while loading shared libraries: libfunc1.so: cannot open shared object file: No such file or directory > sudo cp libfunc1.so /lib > ./app 3 15 > sudo rm /lib/libfunc1.so # 方案二 > ./app ./app: error while loading shared libraries: libfunc1.so: cannot open shared object file: No such file or directory > sudo sh -c "pwd >> /etc/ld.so.conf" > sudo ldconfig > ./app 3 15 > cat /etc/ld.so.conf include /etc/ld.so.conf.d/*.conf /code/code/Makefile > sudo sed -i '2d' /etc/ld.so.conf > sudo ldconfig # 方案三 > ./app ./app: error while loading shared libraries: libfunc1.so: cannot open shared object file: No such file or directory > export LD_LIBRARY_PATH=$(pwd) > ./app 3 15 |

评论