MinGW 4.8.1 C++11 线程支持 [英] MinGW 4.8.1 C++11 thread support

查看:45
本文介绍了MinGW 4.8.1 C++11 线程支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I downloaded the version of MinGW from the official website: http://sourceforge.net/projects/mingw/files/ and installed it on my Windows 7 machine.

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

Running g++ --version gives me g++.exe (GCC) 4.8.1 and I believe GCC 4.8.1 has support for C++11 features, including threads.

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

Running g++ -std=c++11 main.cpp successfully compiles the following program.

//main.cpp
#include <memory>

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

但在以下程序上运行 g++ -std=c++11 main.cpp:

But running g++ -std=c++11 main.cpp on the following program:

//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> 所以我不知道为什么会出现这个错误.

as if <mutex> is not supported. The compiler does not complain about #include <mutex> so I have no idea why I'm getting this error.

推荐答案

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

If I understand well, std threading is still not supported on mingw, but some mingw-w64 builds support it. Fortunately, you can still build 32-bit apps using this version of mingw.

这是构建链接.

这篇关于MinGW 4.8.1 C++11 线程支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆