[英]g++ link to shared library not being compiled
我在/ 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
將您的LD_LIBRARY_PATH
環境變量設置為包含/usr/local/lib
或將/usr/local/lib
到/etc/ld.so.conf
並以根用戶身份運行ldconfig
。
另外,運行ldd a.out
來檢查動態鏈接在您的應用程序上是否正常工作。
讀取ld-linux(8) , ldconfig(8) , ldd(1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.