2011-04-14 115 views
2


我试图在mac OS-X 10.5上测试gcc4.6的线程库。 我通过macports成功编译并安装了gcc4.6。 但最简单的并发hello world程序失败。代码如下:g ++ 4.6 std :: Mac OS-X 10.5上的线程错误

#include <iostream> 
#include <thread> 

void sayhello() {std::cout << "Hello\n";} 
int main(){ 
    std::thread t(sayhello); 
    t.join(); 
} 

我试图编译和使用g++ -Wall -std=c++0x test.cpp 我得到了错误:

'thread' is not a member of 'std'

任何想法导致的问题,如何解决呢? 谢谢!

+0

我对此也感兴趣;从我可以告诉苹果公司对其'4.2'编译器进行的修改在构建更新版本时不可用/被MacPorts(或其他人)使用。如果有人知道不同,我会有兴趣听到它。 – trojanfoe 2011-05-27 09:49:35

回答

2

不幸的是,从OSX 10.6.8开始的pthreads实现缺少一些C++ 0x线程所需的功能。在配置过程中,gcc检测到这个并禁用它们的支持。更多详情,请登录std::thread in MacPorts gcc4.5