编译以下代码时:
#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
这是在带有定制 gcc 4.6.1 的 MacOSX Lion 上运行的。对 gcc 4.6 有效的所有其他 c++0x 功能都非常有用。这是 MacOSX 特定的错误吗?
最佳答案
std::thread
(以及 C++11 线程库的其余部分)仅适用于 gcc 4.6.1 支持的部分平台。不幸的是,MacOSX 不是这些平台之一。
我的广告 Just::Thread库为带有 gcc 4.5 的 32 位 MacOSX 提供了 C++11 线程工具,但尚不支持 gcc 4.6。
关于c++ - 在 MacOSX Lion 上编译 gcc 4.6.1 C++0x 线程代码时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7665978/