c++ - 在 MacOSX Lion 上编译 gcc 4.6.1 C++0x 线程代码时出错

标签 c++ macos gcc c++11

编译以下代码时:

#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/

相关文章:

c++ - 是否可以在运行时在堆上创建一个数组,然后在需要时分配更多空间?

C# 到 C++ 静态类

macos - 该应用程序已损坏,无法打开。删除该应用程序并从 App Store 重新下载

c++ - boost crc 优化在 arm 上失败

c - C-文件处理和EOF

c - 为什么缺少终止“字符是一个警告?

c++ - lldb 未解析的断点通过 C++ api

c++ - 给定迭代器检索容器的比较函数

objective-c - Layer 支持的 NSView,禁用 addSubview 动画

python - 在Mac OS中使用conda降级Opencv