【轉】linux /usr/bin/ld cannot find 解決

來源:互聯網
上載者:User

標籤:

原文網址:http://blog.csdn.net/mzwang123/article/details/6702889

問題:
在linux環境編譯應用程式或lib的source code時常常會出現如下的錯誤訊息:

  • /usr/bin/ld: cannot find -lxxx


這些訊息會隨著編譯不同類型的source code 而有不同的結果出來如:

  • /usr/bin/ld: cannot find -lc
  • /usr/bin/ld: cannot find -lltdl
  • /usr/bin/ld: cannot find -lXtst


其中xxx即表示函式庫檔案名稱,如上例的:libc.so、libltdl.so、libXtst.so。
其命名規則是:lib+庫名(即xxx)+.so。


會發生這樣的原因有以下三種情形:

1 系統沒有安裝相對應的lib
2 相對應的lib版本不對
3 lib(.so檔)的symbolic link 不正確,沒有連結到正確的函式庫檔案(.so)


對於上述三種原因有一篇文章寫的很棒可參考這一篇文章的第4點:
gcc命令祥解


解決方案:
(1)先判斷在/usr/lib 下的相對應的函式庫檔案(.so) 的symbolic link 是否正確
若不正確改成正確的連結目標即可解決問題。

(2)若不是symbolic link 的問題引起,而是系統缺少相對應的lib安裝lib即可解決。

(3)如何安裝缺少的lib:
以上面三個錯誤訊息為例:

錯誤1缺少libc的LIB
錯誤2缺少libltdl的LIB
錯誤3缺少libXtst的LIB 

 

  以Ubuntu為例:
  先搜尋相對應的LIB再進行安裝的作業如:

  apt-cache search libc-dev
apt-cache search libltdl-dev 
apt-cache search libXtst-dev


執行個體:
在進行IMEgcin的Source Code的編譯時間出現以下的錯誤訊息:

/usr/bin/ld: cannot find -lXtst


經檢查後發現是:
lib(.so檔)的symbolic link 不正確

解決方案如下:

cd /usr/lib
ln -s libXtst.so.6 libXtst.so


如果在/usr/lib的目錄下找不到libXtst.so 檔,那麼就表示系統沒有安裝libXtst的函式庫。
解法如下:

apt-get install libxtst-dev

 

 

環境:vmware server + RHEL5.4 +fcitx3.63在執行make時遇到錯誤

[[email protected]  fcitx-3.6.3] make

make  all-recursive
make[1]: Entering directory `/home/oracle/Desktop/fcitx-3.6.3‘
Making all in doc
make[2]: Entering directory `/home/oracle/Desktop/fcitx-3.6.3/doc‘
make[2]: Nothing to be done for `all‘.
make[2]: Leaving directory `/home/oracle/Desktop/fcitx-3.6.3/doc‘
Making all in xpm
make[2]: Entering directory `/home/oracle/Desktop/fcitx-3.6.3/xpm‘
make[2]: Nothing to be done for `all‘.
make[2]: Leaving directory `/home/oracle/Desktop/fcitx-3.6.3/xpm‘
Making all in lib
make[2]: Entering directory `/home/oracle/Desktop/fcitx-3.6.3/lib‘
make[2]: Nothing to be done for `all‘.
make[2]: Leaving directory `/home/oracle/Desktop/fcitx-3.6.3/lib‘
Making all in src
make[2]: Entering directory `/home/oracle/Desktop/fcitx-3.6.3/src‘
gcc -O2 -fno-strength-reduce -g -O2   -D_ENABLE_TRAY    -Wall -lXpm -lXtst -lpthread  -o fcitx IC.o ime.o InputWindow.o KeyList.o main.o MainWindow.o MyErrorsHandlers.o punc.o py.o PYFA.o pyMapTable.o pyParser.o sp.o tools.o ui.o table.o xim.o qw.o tray.o TrayWindow.o DBus.o vk.o about.o QuickPhrase.o AutoEng.o extra.o internalVersion.o ImeRemote.o ../lib/libXimd.a -lX11 
/usr/bin/ld: cannot find -lXtst
collect2: ld returned 1 exit status
make[2]: *** [fcitx] Error 1
make[2]: Leaving directory `/home/oracle/Desktop/fcitx-3.6.3/src‘
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/oracle/Desktop/fcitx-3.6.3‘
make: *** [all] Error 2

經過檢查在目錄  /usr/bin/ld下面沒有發現lXtst

【轉】linux /usr/bin/ld cannot find 解決

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.