Reputation: 91
I did my homework and searched for an answer here and on the net. The simple code below is not compiling:
#include <thread>
#include <iostream>
void hello()
{
std::cout << "Hello from thread " << std::endl;
}
int main()
{
std::thread t1(hello);
t1.join();
return 0;
}
It's very simple code, but I'm getting the following errors:
Thread_Cpp11_002.cpp: In function 'int main()'
Thread_Cpp11_002.cpp:14:5: error: 'thread' is not a member of 'std'
Thread_Cpp11_002.cpp:14:17: error: expected ';' before 't1'
Thread_Cpp11_002.cpp:15:5: error: 't1' was not declared in this scope
And I've tried a lot of things, none of which have worked:
t1
using thread
instead of std::thread
-pthread
, -std=gnu++11
, -std=c++0x
, -std=c++11...
So, I think this question it worth being posted here.
These compilation were done through the command line. After I have it working I will try with Code::Blocks 12.11, which worked fine for C++98.
Remember, I'm using Windows Vista.
Upvotes: 2
Views: 1272
Reputation: 2611
This is a well-known issue with some builds of MinGW (just search for mingw thread
in your favorite engine). If you need thread support, you have to use another library (such as boost or the native Windows API) or a different build.
Upvotes: 1