在linux下运行程序时,发现了error while loading shared libraries这种错误,一时间不知道解决办法,在网上搜索,终于解决了:
./tests: error while loading shared libraries: xxx.so.0:cannot open shared object file: No such file or directory
出现这类错误表示,系统不知道xxx.so放在哪个目录下,这时候就要在/etc/ld.so.conf中加入xxx.so所在的目录。
1、先确定自己的so文件所在的目录
一般而言,有很多的so会存放在/usr/local/lib这个目录底下,去这个目录底下找,没有发现自己所需要的.so文件。然后在/usr/local/mysql/lib这个目录下找到了所需要的.so文件。
# vi /etc/ld.so.conf
显示:
include ld.so.conf.d/*.conf
原来是引用到了ld.so.conf.d这个目录下的所有conf结尾的文件
# cd ld.so.conf.d
看到mysql-x86_64.conf
# vi ./mysql-x86_64.conf
加入/usr/local/mysql/lib,保存之后,再运行:/sbin/ldconfig –v更新一下配置即可。
ldconfig :他是链接库设置程序。告诉系统哪里寻找 .so 库文件的,运行他会刷新 ld 缓存。