2014-04-24 64 views
5

我想編譯一個共享庫,它沒有足夠的libstdC++來運行它,這意味着我需要將libstdC++靜態鏈接到庫中。我想直接鏈接到的libstdC++一(-Wl,-Bstatic -L/path/to/lib64 -lstdc++),但我發現,似乎表明我的libstdC++一個未用PIC鏈接錯誤:。如何使用PIC編譯gnu libstdC++。a?

/usr/bin/ld: lib64/libstdc++.a(compatibility.o): relocation R_X86_64_32 against `typeinfo for __cxxabiv1::__forced_unwind' can not be used when making a shared object; recompile with -fPIC 
lib64/libstdc++.a: could not read symbols: Bad value 

我試圖重新編譯GCC CFLAGS =「 - fPIC」和CXXFLAGS =「 - fPIC」,但這似乎沒有做任何事情。

幫助?

回答

6

這個想法是通過--with-pic選項configure。 GCC構建是一個非常複雜的有多個階段的野獸,所以傳遞一個CFLAGS變量可能無法按預期工作。

+0

這是記錄在任何地方嗎?它不在http://gcc.gnu.org/install/configure.html – bobpoekert

+0

但是,如果您更改爲/libstdC++ - v3子目錄並運行'configure --help',那麼您將會看到它。 – oakad

+1

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28811 - 與stdC++ libs的圖片問題有一個相當動盪的歷史。 – oakad

0

閱讀GCC configure documentation

指定主機代碼應被內置到與位置無關的 機器代碼(與-fPIC),允許它被內共享 用於:建立GCC時,因爲它在本說明書中說我使用該標誌--enable-host-shared庫,但產生稍慢的編譯器。