[英]g++ link to shared library not being compiled
I have these shared library files in /usr/local/lib: 我在/ usr / local / lib中有这些共享库文件:
libopenbabel.so
libopenbabel.so.4
libopenbabel.so.4.0.2
libopenbabel.so is actually a link to libopenbabel.so.4 and libopenbabel.so.4 is actually a link to libopenbabel.so.4.0.2 libopenbabel.so实际上是指向libopenbabel.so.4的链接,而libopenbabel.so.4实际上是指向libopenbabel.so.4.0.2的链接。
when I compile my file with this command: 当我使用以下命令编译文件时:
g++ test.cpp -L/usr/local/lib -lopenbabel
and then try to run a.out, I get this error: 然后尝试运行a.out,出现此错误:
./a.out: error while loading shared libraries: libopenbabel.so.4: cannot open shared object file: No such file or directory
Implying that the compiler is finding libopenbabel.so but running into an error when following that link to libopenbabel.so.4 which is in the exact same directory. 暗示编译器正在找到libopenbabel.so,但在链接到位于完全相同目录的libopenbabel.so.4时遇到错误。 Any ideas on why this is happening / how I can fix it?
关于为什么发生这种情况/如何解决的任何想法?
Output of ls -l in /usr/local/lib: / 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
Either set your LD_LIBRARY_PATH
environment variable to contain /usr/local/lib
or add /usr/local/lib
to /etc/ld.so.conf
and run ldconfig
as root. 将您的
LD_LIBRARY_PATH
环境变量设置为包含/usr/local/lib
或将/usr/local/lib
到/etc/ld.so.conf
并以根用户身份运行ldconfig
。
Also, run ldd a.out
to check that dynamic linking works well on your app. 另外,运行
ldd a.out
来检查动态链接在您的应用程序上是否正常工作。
Read ld-linux(8) , ldconfig(8) , ldd(1) 读取ld-linux(8) , ldconfig(8) , ldd(1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.