menu

秋梦无痕

一场秋雨无梦痕,春夜清风冻煞人。冬来冷水寒似铁,夏至京北蟑满城。

Avatar

"error while loading shared libraries"的解决方法

执行程序时出现如下错误时:
$ ./test: 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 所在的路径。

通常情况下运行make install之后,xxx.so文件是放在/usr/local/lib目录下的,所以在/etc/ld.so.conf 中加入 /usr/local/lib 即可解决此问题。

当然,在保存 /etc/ld.so.conf 后,还需要执行
$ /sbin/ldconfig –v
来更新一下才会生效。

另外一种情况,就是运行 make install 之后立即进行测试,有时候也要执行 /sbin/ldconfig –v 才能找到 .so 文件。