所以我一直試圖通過使用MinGW編譯器來獲得下面的代碼來編譯和運行在Windows上。MinGW和std :: thread
#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的-構建:thread-win32
- MinGW的-構建:thread-posix
- 的MinGW-W64:stdthread experimental rubenvb
- 的MinGW-W64:stdthread experimental rubenvb 4.7
1號不起作用,因爲GCC apparently only supports 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再做一次編譯,但他們不「T輸出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 tracker和其他一些職位,那建議使用-pthread
,這根本沒有幫助。
我也嘗試過手動鏈接winpthread
和pthread
,但這也沒有做任何事情。
還有-std=c++11
和-std=gnu++11
沒有什麼區別...
我真的失去了,現在不知道,如果它是在所有可能得到一個MinGW的版本,支持std::thread
,但也許我只是忽略了一些編譯器標誌。我希望有人能幫助我!
花費了幾個小時才找到解決方案,最後2點工作!謝謝! – Massimo