2009-12-18 45 views
2

我已經建立libshared.so與依賴於libshared_dependent.so如何在編譯期間解析共享庫鏈接(GCC)?

現在,我編譯app.bin這是使用libshared.so,現在在編譯時GCC要我指定-lshared_dependent其他明智的是它給出錯誤,找不到一些符號。

有什麼辦法通過,在編譯的時候,我不指定-lshared_dependent,我想這只是指定-lshared工作需要?

+0

任何libshared.so取決於@Sateesh它要求我改變很多很多的makefile。我改變了一個共享文件的依賴性,現在我不想更改其他項目的makefile。 – SunnyShah 2009-12-18 07:03:30

+0

但爲什麼你不想指定依賴庫? – sateesh 2009-12-18 07:04:35

回答

4

你只需要連接libshared.so當你到libshared_dependent.so產生libshared.so。

gcc -shared -o libshared.so -lshared_dependant file1.o file2.o 

這樣,當你鏈接您的應用程序li​​bshared.so它會連接到

1

您不需要將app.bin鏈接到libshared_dependent.so。

也就是說,鏈接器將要驗證libshared.so中的符號可以找到,所以它將需要找到libshared_dependent.so爲了做到這一點。如果libshared_dependent.so與libshared.so不在同一目錄中,則需要使用鏈接器選項-rpath-link指定libshared_dependent.so的路徑。

因爲-rpath鏈接是一個連接器選項,你需要告訴GCC通過向它傳遞給鏈接器:

gcc -Wl,-rpath-link,/directory-that-libshared_dependent-is-in