私はMinGWで私のC++ 11プロジェクト(最近C++ 11に移行)をコンパイルしたいと思います。そして私は "std :: thread not found"のようなC++ 11コードについてのエラーをコンパイルしています。MinGWでC++ std :: threadコードをコンパイルするには?
最後のMinGWをgcc 5.3.0(2015年12月)で使用しました。最後に、私は私の大きなプロジェクトをコンパイルする前に、この例のみをコンパイルしたいと思います:
#include <iostream>
#include <thread>
#include <chrono>
void foo()
{
// simulate expensive operation
std::this_thread::sleep_for(std::chrono::seconds(1));
}
void bar()
{
// simulate expensive operation
std::this_thread::sleep_for(std::chrono::seconds(1));
}
int main()
{
std::cout << "starting first helper...\n";
std::thread helper1(foo);
std::cout << "starting second helper...\n";
std::thread helper2(bar);
std::cout << "waiting for helpers to finish..." << std::endl;
helper1.join();
helper2.join();
std::cout << "done!\n";
}
(ソース:http://en.cppreference.com/w/cpp/thread/thread/join)
私は "G ++ -std = C++ 11 main.cppに" を試してみましたそして「G ++ main.cppに-std = C++ 0xの」私はいつも、それらの次のエラーがあります。
main.cpp: In function 'void foo()':
main.cpp:8:10: error: 'std::this_thread' has not been declared
std::this_thread::sleep_for(std::chrono::seconds(1));
^
main.cpp: In function 'void bar()':
main.cpp:14:10: error: 'std::this_thread' has not been declared
std::this_thread::sleep_for(std::chrono::seconds(1));
^
main.cpp: In function 'int main()':
main.cpp:20:5: error: 'thread' is not a member of 'std'
std::thread helper1(foo);
^
main.cpp:23:5: error: 'thread' is not a member of 'std'
std::thread helper2(bar);
^
main.cpp:26:5: error: 'helper1' was not declared in this scope
helper1.join();
^
main.cpp:27:5: error: 'helper2' was not declared in this scope
helper2.join();
^
https://stackoverflow.com/questions/37358856/does-mingw-w64-support-stdthread-out-of-the-box-when-using-the-win32-threading、mingw(少なくとも古いバージョン)は、std :: threadをそのままの状態でサポートしていません – nos