2014-01-18 46 views
0

好的,我在CodeBlocks IDE 12.11上用MinGW編譯以下簡單的代碼塊(在cplusplus.com上找到)(單獨下載,截至今天也是最新版本)。 的事情是,它顯示了在編譯以下錯誤:奇怪的線程問題

12: error: 'thread' was not declared in this scope

12: error: expected ';' before 't1'

13: error: 't1' was not declared in this scope

#include <iostream> 
#include <thread> 

using namespace std; 

void hello(void){ 
    cout << "hey there!" << endl; 
} 

int main() 
{ 
    thread t1(hello); 
    t1.join(); 
    return 0; 
} 

在線程不GCC支持完全我是否需要標誌添加到我的編譯器,以及如何做到這一點的一個代碼塊項目?在此先感謝

+0

檢查g ++版本。在'線索'頭文件中查看它是否定義了線程類。 – vrdhn

+0

您是否注意到頁面頂部的黃色驚歎號表示它是C++ 11功能並且可能不被所有編譯器支持? –

+0

@Vardhan g ++版本4.8.1。此外線程頭文件包括類線程 – TheDillo

回答

1

--std=c++11 -pthread添加到您的編譯器標記

+0

他爲什麼要添加-pthread? – IllusiveBrian

+0

添加對多線程的支持 – prajmus

+0

試過但它沒有工作:( – TheDillo