Mac OS-X 10.5 上的 g++4.6 std::thread 错误
我试图在 mac OS-X 10.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'
知道导致问题的原因以及如何解决它吗? 谢谢!
I was trying to test thread library of gcc4.6 on mac OS-X 10.5.
I successfully compiled and installed gcc4.6 by macports.
But the simplest concurrent hello world program failed. The code is like:
#include <iostream>
#include <thread>
void sayhello() {std::cout << "Hello\n";}
int main(){
std::thread t(sayhello);
t.join();
}
I tried to compile and used g++ -Wall -std=c++0x test.cpp
I got the error:
'thread' is not a member of 'std'
Any idea what cause the problem and how can I fix it?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,从 OSX 10.6.8 开始,pthreads 实现缺少 C++0x 线程所需的一些功能。在配置过程中,gcc 会检测到这一点并禁用对它们的支持。更多详细信息,请访问 MacPorts gcc4.5 中的 std::thread
Unfortunately, pthreads implementation as of OSX 10.6.8 lacks some required features for C++0x threads. During configure, gcc detects this and disable support for them. More details at std::thread in MacPorts gcc4.5