我在/ usr / local / lib中有这些共享库文件:
libopenbabel.so
libopenbabel.so.4
libopenbabel.so.4.0.2
libopenbabel.so实际上是libopenbabel.so.4的链接,而libopenbabel.so.4实际上是libopenbabel.so.4.0.2的链接
使用此命令编译文件时:
g++ test.cpp -L/usr/local/lib -lopenbabel
然后尝试运行a.out,我收到此错误:
./a.out: error while loading shared libraries: libopenbabel.so.4: cannot open shared object file: No such file or directory
暗示编译器正在查找libopenbabel.so,但在跟随指向完全相同目录的libopenbabel.so.4的链接时遇到错误。关于为什么会这样做/我如何解决它的任何想法?
在/ usr / local / lib中输出ls -l:
total 33772
drwxr-xr-x 7 root root 4096 Mar 22 01:24 .
drwxr-xr-x 10 root root 4096 Aug 20 2013 ..
drwxr-xr-x 3 root root 4096 Mar 21 23:45 cmake
lrwxrwxrwx 1 root root 13 Mar 21 23:45 libinchi.so -> libinchi.so.0
lrwxrwxrwx 1 root root 17 Mar 21 23:45 libinchi.so.0 -> libinchi.so.0.4.1
-rw-r--r-- 1 root root 3315565 Mar 22 01:04 libinchi.so.0.4.1
lrwxrwxrwx 1 root root 17 Mar 21 23:45 libopenbabel.so -> libopenbabel.so.4
lrwxrwxrwx 1 root root 21 Mar 21 23:45 libopenbabel.so.4 -> libopenbabel.so.4.0.2
-rw-r--r-- 1 root root 31232420 Mar 22 01:04 libopenbabel.so.4.0.2
drwxr-xr-x 3 root root 4096 Mar 21 23:45 openbabel
drwxr-xr-x 2 root root 4096 Mar 22 01:24 pkgconfig
drwxrwsr-x 4 root staff 4096 Mar 3 12:57 python2.7
drwxrwsr-x 3 root staff 4096 Dec 22 18:25 python3.2
答案 0 :(得分:3)
将LD_LIBRARY_PATH
环境变量设置为包含/usr/local/lib
或将/usr/local/lib
添加到/etc/ld.so.conf
并以root身份运行ldconfig
。
另外,运行ldd a.out
检查动态链接是否适用于您的应用。