问题描述
我从官方网站下载了MinGW的版本:并将其安装到我的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>一个(新的int);
返回0;
}
但是运行 g ++ -std = c ++ 11 main.cpp
在以下程序中:
// main.cpp
#include <互斥>
int main(){
std :: mutex myMutex;
返回0;
$ / code>
给出错误:
main.cpp:函数中`int main()`:
main.cpp:5:5:错误:'mutex'不是'std'$的成员b $ b std :: mutex myMutex;
^
main.cpp:5:16:error:expected';'在'myMutex'之前
std :: mutex myMutex;
^
好像
<互斥体>
不受支持。编译器不会抱怨 #include< mutex>
,所以我不知道为什么我得到这个错误。
解决方案
如果我理解得很好,mdw仍然不支持std线程,但是一些mingw-w64构建支持它。幸运的是,您仍然可以使用此版本的mingw构建32位应用程序。
以下是。
I downloaded the version of MinGW from the official website: http://sourceforge.net/projects/mingw/files/ and installed it on my Windows 7 machine.
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.
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;
}
But running g++ -std=c++11 main.cpp
on the following program:
//main.cpp
#include <mutex>
int main() {
std::mutex myMutex;
return 0;
}
gives errors:
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;
^
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.
解决方案 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.
Here is the link for the builds.
这篇关于MinGW 4.8.1 C ++ 11线程支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!