开发者

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

When compiling the following code:

#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;
}

using:

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

I get the following error:

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开发者_如何学C:2: error: ‘t’ was not declared in this scope

This is on MacOSX Lion with a custom built gcc 4.6.1. All the other c++0x features that are valid for gcc 4.6 works like a charm. Is this a MacOSX specific error?


std::thread (and the rest of the C++11 thread library) is only available for some of the platforms supported by gcc 4.6.1. Unfortunately for you, MacOSX is not one of those platforms.

My commercial Just::Thread library provides the C++11 thread facilities for 32-bit MacOSX with gcc 4.5, but gcc 4.6 is not supported yet.


See http://gcc.gnu.org/PR50196 - Mac OS X doesn't support some parts of pthreads that we rely on. Building the latest version won't help, but it might be fixed for GCC 4.7

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜