我试图在mac X10.5上测试gcc4.6的线程库。我通过macports成功编译并安装了gcc4.6。但是最简单的并发hello world程序失败了。代码如下:
#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'
你知道是什么导致了这个问题吗?我该如何解决它?谢谢!
发布于 2011-07-14 21:20:21
不幸的是,从OSX10.6.8开始,pthread实现缺少一些C++0x线程所需的特性。在配置过程中,gcc会检测到这一点,并禁用对它们的支持。有关更多细节,请访问std::thread in MacPorts gcc4.5
https://stackoverflow.com/questions/5668829
复制相似问题