2015-10-06 213 views
0

我試圖編譯和鏈接一些.c文件。我一直在使用Eclipse IDE作爲C/C++開發人員,在我的本地機器上,我可以毫無問題地進行編譯。但是,當我嘗試編譯和鏈接RedHat操作系統中的相同文件(gcc版本是4.9.2-6在這個操作系統)我有問題。我在編譯時得到了一些警告,但這些都很好,我認爲,我只是忽略了,應用程序仍然運行良好。這裏是我執行的命令和相關的輸出:與共享庫鏈接

gcc -O0 -g3 -Wall -c -fmessage-length=0 -std=c99 -MMD -MP -MF"example.d" -MT"example.d" -o "example.o" "example.c" 

warning: suggest parentheses around assignment used as truth value [-Wparentheses] 
warning: implicit declaration of function ‘wait’ [-Wimplicit-function-declaration] 

這會生成兩個文件example.d和example.o。然後,我試圖把它們聯繫起來,沒有運氣,用下面的命令:

gcc -Xlinker -L/usr/lib -lrt -static -pthread example.o -o example 
/usr/bin/ld: cannot find -lrt 
/usr/bin/ld: cannot find -lpthread 
/usr/bin/ld: cannot find -lc 
collect2: error: ld returned 1 exit status 

的命令採取直接從Eclipse中生成的,並且工作在我的本地計算機(Ubuntu的OS)就好了,但不是在RedHat環境。最後的命令不起作用,有和沒有-L選項。我想在-L目錄是好的,因爲我運行,例如,

locate libpthread.so 

,我得到的位置之一是/ usr/lib目錄(也是在/ usr/lib64下,但是沒有工作)。

任何幫助將不勝感激! :)

回答

2

如果您嘗試鏈接靜態可執行文件,它將查找*.a版本的庫,而不是您通常想要的。刪除-static標誌。或者你可以安裝靜態庫,如果你真的想。它也不應該明確地添加-L/usr/lib

+0

這正是問題所在。一旦我放下了 - 靜止的旗幟,一切都奏效了,謝謝! :) – Lucia