linux 缺少动态连接库.so(cannot open shared object file: No such file or directory)解决办法
对于自行编译的库,如opus,opencv等,其自带的可执行程序在使用时有时候会报cannot open shared object file: No such file or directory
的错误,事实上,相关的依赖库已经安装或编译了,这是由于大部分的自编译库都是默认存放在/usr/local/lib
中的,而Linux系统通常只会去/usr/lib
中寻找库文件,这就导致无法加载库文件导致报错。
解决方法(三选一)
-
使用ln命令对
*.so
文件创建链接,放到/usr/lib
中ln -s /your install path/xxx.so /usr/lib sudo ldconfig
-
修改宏变量
LD_LIBRARY_PATH
在修改~/.bashrc文件,在其中增加一条 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/your install path
-
修改/etc/ld.so.conf,然后刷新
vim /etc/ld.so.conf add /where/you/install/lib sudo ldconfig