About c++ : Thread-doesnt-work-with-an-error-Enable-multithreading-to-use-stdthread-Operation-not-permitted
Question Detail
I created and executed a simple thread on my system. when I execute this program, I have the error message : Enable multithreading to use std::thread: Operation not permitted
some details about my system :
linux ubuntu 13.10
g++ 4.8.1
I compile the source code including the library pthread
The source code:
#include using namespace std; void func(void) { It seems that you are trying to use C++11 threads. If it is true, then correct #include Hint: when you are using threads in a static linked library and use this library in an executable, then you have to add the flag -pthread to the link command for the executable. Example: g++ Obj1.o Obj2.o MyStaticLib.a -o MyExecutable -pthread
#include
cout << "test thread" << endl;
}
int main() {
cout << "start" << endl;
thread t1 (func);
t1.join();
cout << "end" << endl;
return 0;
}
Question Answer
compile with g++ -std=c++11 q.cpp -lpthread (dependency order matters for newer g++)