关于cannot open shared object file: No such file or directory的解决

0x00

今天在安装Nginx的时候发现openssl、pcre、zlib都装好了,启动的时候发现如下提示

# ./nginx ./nginx: error while loading shared libraries: libpcre.so.0: cannot open shared object file: No such file or directory
# ./nginx: error while loading shared libraries: libpcre.so.0: cannot open shared object file: No such file or directory -bash: ./nginx:: No such file or directory

然后在百度找了一通发现解决的方法很多,自己记录了一下解决的方法如下:

0x01

如果共享库文件安装到了/lib/usr/lib目录下,那么需执行一下ldconfig命令

0x02

# cat /etc/ld.so.conf include ld.so.conf.d/*.conf
# echo “/usr/local/lib” >> /etc/ld.so.conf
# ldconfig

0x03

/lib/usr/lib” 目录下,但是又不想在/etc/ld.so.conf中加路径(或者是没有权限加路径). 那可以export一个全局变量LD_LIBRARY_PATH,然后运行程序的时候就会去这个目录中找共享库

可以添加用户环境变量来解决

export LD_LIBRARY_PATH=/usr/local/mysql/lib:$LD_LIBRARY_PATH