所以我一直在尝试使用MinGW编译器在Windows上编译和运行以下代码。
#include <iostream>
#include <thread>
void test()
{
std::cout << "test" << std::endl;
}
int main()
{
std::thread t(test);
}
我正在使用以下命令进行编译:
g++ -std=c++11 test.cpp -o test.exe
现在的问题是应该使用的MinGW版本,我已经尝试过我所知道的所有版本。
- MinGW的-建立: 线程的Win32
- MinGW的-建立: 线程POSIX
- MinGW的-W64: stdthread实验rubenvb
- MinGW的-W64: stdthread实验rubenvb 4.7
自GCC以来,1号不起作用 显然只支持 pthread内部的东西。
2号确实编译,它基本上甚至输出 test
(请参阅输出的最后一行),但它也会因错误而崩溃:
terminate called without an active exception
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
test
3号和4号再次编译,但它们不输出 test
而是立即崩溃,但具有更具描述性的输出:
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
谷歌当然把我带到了 GCC bug跟踪器 和其他一些建议使用的帖子 -pthread
,这根本没有帮助。
我也试过手动链接 winpthread
和 pthread
,但这也没有做任何事情。
两者之间也没有区别 -std=c++11
和 -std=gnu++11
...
我现在真的迷路了,不知道,如果有可能得到一个支持的MinGW版本 std::thread
,但也许我只是忽略了一些编译器标志。我希望有人可以帮助我!