簡體   English   中英

在MacOSX Lion上編譯gcc 4.6.1 C ++ 0x線程代碼時出錯

[英]Error when compiling gcc 4.6.1 C++0x threading code on MacOSX Lion

編譯以下代碼時:

#include <iostream>
#include <thread>

using namespace std;

void hello()
{
        cout << "Hello World!" << endl;
}

int main()
{
        cout << "starting" << endl;
        thread t(hello);
        t.join();
        cout << "ending" << endl;
        return 0;
}

使用:

$ g++-4.6.1 -std=c++0x -pthread threading.cpp

我收到以下錯誤:

threading.cc: In function ‘int main()’:
threading.cc:13:2: error: ‘thread’ was not declared in this scope
threading.cc:13:9: error: expected ‘;’ before ‘t’
threading.cc:14:2: error: ‘t’ was not declared in this scope

這是在MacOSX Lion上使用自定義構建的gcc 4.6.1。 對gcc 4.6有效的所有其他c ++ 0x特性就像魅力一樣。 這是MacOSX特定的錯誤嗎?

std::thread (以及C ++ 11線程庫的其余部分)僅適用於gcc 4.6.1支持的某些平台。 不幸的是,MacOSX不是那些平台之一。

我的商業Just :: Thread庫為32位MacOSX和gcc 4.5提供了C ++ 11線程工具,但是還不支持gcc 4.6。

請參閱http://gcc.gnu.org/PR50196 - Mac OS X不支持我們依賴的pthread的某些部分。 構建最新版本無濟於事,但GCC 4.7可能會修復

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM