我从官网下载了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/