2011-03-22 45 views
5

我在linux下UBUNTU下工作在eclipse 10.10,使用Synaptic pkg管理器安裝boost-dev軟件包1.40。我是Linux新手,這個提升pkg。我嘗試創建一個新的項目,並寫上:不能編譯,如果包括提升/線程在Linux Ubuntu 10.10

#include <boost/thread.hpp> 
int main(int argc, char* argv[]){ 
} 

我不包括任何東西,或任何地方寫這樣並行線程東西。 試圖建立的時候,它說:

/usr/include/boost/config/requires_threads.hpp:47: error: #error "Compiler threading support is not turned on. Please set the correct command line options for threading: -pthread (Linux), -pthreads (Solaris) or -mthreads (Mingw32)" 
In file included from /usr/include/boost/thread/thread.hpp:12, 
       from /usr/include/boost/thread.hpp:13, 
       from ../main.cpp:8: 
/usr/include/boost/thread/detail/platform.hpp:67: error: #error "Sorry, no boost threads are available for this platform." 
In file included from /usr/include/boost/thread.hpp:13, 
       from ../main.cpp:8: 
/usr/include/boost/thread/thread.hpp:19: error: #error "Boost threads unavailable on this platform" 

等等,很多相關的多個錯誤的提振。 我試圖將-pthread,-pthreads,-lpthread添加到我認爲可以的地方,但沒有解決問題。 我忘了提及,我試圖在eclipse中構建項目,我不在命令行工作,但我也嘗試了g ++ -pthread main.cpp,它給出了完全相同的錯誤。 請詳細說明或stepbystep解決方案,因爲您在這裏回答的一些問題對我來說只是中文。我只想讓一件簡單的事情運行,甚至不理解問題。甚至不明白那個錯誤信息,它要我做什麼。 基本上我做了:安裝eclipse,將上述內容寫入新項目,使用sinaptic pkg管理器安裝libboost 1.4,並重新啓動所有內容並嘗試編譯。我得到了錯誤。看不到發生了什麼,或者我錯過了什麼。 (我有libc-dev) 堆棧現在真的流淌了。需要一些睡眠來降溫。謝謝你們的幫助!

+1

哇,那是我第一次聽說過Linux的稱爲Linux 10.10。毫無疑問,Ubuntu肯定會產生一些影響。 :-) – Shinnok 2011-03-22 10:58:43

+0

對不起,我是新來的所有這些Linux和Ubuntu的東西,但是,是的,這是一個錯誤:)有趣,雖然 – andrissh 2011-03-22 11:15:03

+0

顯示您的編譯命令行完全在你的問題。 Boost線程只是包裝底層的OS線程,所以通過包含boost/thread.hpp來請求pthreads。 – Duck 2011-03-22 13:14:31

回答

2

由於錯誤信息說:傳-pthread編譯器:

g++ -pthread yourfile.cpp 

另外,Debian,請確保你已經安裝了libc-dev

+0

謝謝,它試過這個,但它提供了完全相同的消息 - 這次它將它寫入終端當然。我想知道,我如何在eclipse中運行而不是終端。 /usr/include/boost/config/requires_threads.hpp:47:error:#error「編譯器線程支持未打開,請爲線程設置正確的命令行選項:-pthread(Linux),-pthreads(Solaris)或-mthreads(Mingw32)「 – andrissh 2011-03-22 10:45:13

+0

我有libc-dev。任何其他提示? – andrissh 2011-03-22 11:13:15

6
#include <boost/thread.hpp> 

int main(int argc, char *argv[]) { 
    return 0; 
} 

編譯g++ test.cpp -pthread -lboost_thread

+0

感謝您的提示!完全相同的錯誤! (我看到你添加了返回0 :) – andrissh 2011-03-22 14:29:42

+0

你的軟件包肯定有東西壞了。嘗試重新安裝boost和g ++。 – orlp 2011-03-22 14:31:19

+0

嗯。試過也...同樣的錯誤。我應該現在安裝10.04而不是10.10? – andrissh 2011-03-22 15:00:38

11

這個問題是一個衆所周知的從這樣一箇舊版本的提升。您正在使用gcc/g ++ 4.7進行編譯,其中對pthread的引用已更改爲GLIBCXX_HAS_GTHREADS,因此boost無法找到pthread並將其禁用。

所以,你有兩個選擇:

1)升級boost_dev到最後一個版本(我認爲這是固定的1.50+)。

2)修補你的boost包含文件(我已經完成了這個);只需編輯

「你升壓文件夾」 /include/config/stdlib/libstdcpp3.hpp

和變化:

#ifdef __GLIBCXX__ // gcc 3.4 and greater: 
# if defined(_GLIBCXX_HAVE_GTHR_DEFAULT) \ 
     || defined(_GLIBCXX__PTHREADS) 
     // 
     // If the std lib has thread support turned on, then turn it on in Boost 
     // as well. We do this because some gcc-3.4 std lib headers define _REENTANT 
     // while others do not... 
     // 
#  define BOOST_HAS_THREADS 
# else 
#  define BOOST_DISABLE_THREADS 
# endif 

添加新的指令中的條件:

#ifdef __GLIBCXX__ // gcc 3.4 and greater: 
# if defined(_GLIBCXX_HAVE_GTHR_DEFAULT) \ 
     || defined(_GLIBCXX__PTHREADS) \ 
     || defined(_GLIBCXX_HAS_GTHREADS) // gcc 4.7 
     // 
     // If the std lib has thread support turned on, then turn it on in Boost 
     // as well. We do this because some gcc-3.4 std lib headers define _REENTANT 
     // while others do not... 
     // 
#  define BOOST_HAS_THREADS 
# else 
#  define BOOST_DISABLE_THREADS 
# endif 

錯誤描述和修復的Linux和Windows在這裏:

https://svn.boost.org/trac/boost/ticket/6165

享受。

3

您需要安裝升壓線程庫:

sudo apt-get install libboost-thread-dev