gcc - MinGW 4.8.1 C++11 线程支持

标签 gcc c++11 g++ mingw

我从官网下载了MinGW的版本:http://sourceforge.net/projects/mingw/files/并将其安装在我的 Windows 7 机器上。

运行 g++ --version给我 g++.exe (GCC) 4.8.1我相信 GCC 4.8.1 支持 C++11 特性,包括线程。

运行 g++ -std=c++11 main.cpp成功编译以下程序。

//main.cpp
#include <memory>

int main() {
    std::unique_ptr<int> a(new int);
    return 0;
}

但是正在运行 g++ -std=c++11 main.cpp在以下程序中:
//main.cpp
#include <mutex>

int main() {
    std::mutex myMutex;
    return 0;
}

给出错误:
main.cpp: In function `int main()`:
main.cpp:5:5: error: 'mutex' is not a member of 'std'
    std::mutex myMutex;
    ^
main.cpp:5:16: error: expected ';' before 'myMutex'
    std::mutex myMutex;
                ^

好像<mutex>不支持。编译器不会提示 #include <mutex>所以我不知道为什么我会收到这个错误。

最佳答案

如果我理解得很好,mingw 仍然不支持标准线程,但一些 mingw-w64 版本支持它。幸运的是,您仍然可以使用此版本的 mingw 构建 32 位应用程序。

这是link for the builds .

关于gcc - MinGW 4.8.1 C++11 线程支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24009821/

相关文章:

c++ - SFML游戏无法在Windows上编译

c++ - 似乎无法在碰撞、散列时打破 while 循环

c++ - 这个指针和所有参数在调用后都是空的(但之前没问题)

c++ - undefined reference to vtable 错误是由现代 g++ 编译器解决的吗?

gcc - 如何获取当前平台的BFD架构规范?

c++ - 访问基类的私有(private)变量时派生类出错

c++ - 静态变量阴影全局

gcc - MSYS2-安装gcc或工具链?

c++ - 泛化编译时和运行时评估

variables - 在单个函数中回收变量名