2012-07-08 46 views
0

我遇到問題:我使用Boost編寫代碼(locks.hpp)。我的服務器正在運行x64 Ubuntu(Linux)。當我編譯這個代碼與-m64,它建立罰款。但是,當我嘗試編譯爲-m32,我得到這些錯誤:G ++無法使用Boost for x86編譯代碼

g++ -fPIC -m32 -shared -Wl,-soname,test.so -ldl -o test.so test.cpp -lboost_thread 

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../libboost_thread.so when searching for -lboost_thread 
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../libboost_thread.a when searching for -lboost_thread 
/usr/bin/ld: skipping incompatible //usr/lib/libboost_thread.so when searching for -lboost_thread 
/usr/bin/ld: skipping incompatible //usr/lib/libboost_thread.a when searching for -lboost_thread 
/usr/bin/ld: cannot find -lboost_thread 
collect2: ld returned 1 exit status 

我在做什麼錯?謝謝!

+1

雖然我有G ++沒有經驗:是有可能,你有升壓沒有32位版本(有點我會怎樣解釋「不兼容東西「)... – MFH 2012-07-08 22:04:59

+3

你確定你安裝了32位boost庫嗎? – fvu 2012-07-08 22:05:06

+0

@fvu你能給我一個命令來安裝32位升壓庫在X64 Ubuntu的? – Robert 2012-07-08 22:35:10

回答

2

您需要32位版本的線程庫。您的問題的answer已經在stackoverflow.com上。從源代碼構建提升時,請使用地址模型選項。 Boost爲Linux上的構建提供了很好的documentation

bjam address-model=32 
+0

感謝您的回答。你能告訴我如何將這些編譯的頭文件和庫添加到g ++命令? – Robert 2012-07-09 12:46:03

+0

您可以使用boost「bcp」實用程序:http://www.boost.org/doc/libs/1_50_0/tools/bcp/doc/html/index.html – Dan 2012-07-10 15:39:03

+0

@Dan如果我在64位上使用BCP並將生成的文件夾移動到32位機器上,它仍然可以工作嗎? – 2014-08-17 12:40:13

3

嘗試安裝32位提升包裝:

sudo apt-get install libboost-thread-dev:i386 
+0

不幸的是,這會強制替換當前的64位開發環境(編譯器和許多軟件包),因此這太具侵入性了。有沒有辦法同時擁有32位和64位? – arielf 2014-07-10 00:16:26

+0

@arielf,是的,有,但我不知道Ubuntu,所以我不知道該怎麼做。我驚訝於上面的命令_replaces_任何東西,而不是僅僅添加一個新的包。 – 2014-07-10 09:13:52

+0

以我的經驗,這只是一個提升的問題。我有許多(C語言)庫並排安裝(多拱:32和64位),沒有問題。不知道爲什麼boost * * -dev:i386'包創建者強制它與默認(amd64)boost'-dev'包衝突。由於我已經構建/安裝了幾個依賴於64位boost版本的軟件包,他的':i386'軟件包中的'replaces'子句強制刪除1)64位boost版本和2)所有依賴它的軟件包。 :( – arielf 2014-07-10 21:17:12