• Uncategorized

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
#include

using namespace std;

void func(void) {
cout << "test thread" << endl; } int main() { cout << "start" << endl; thread t1 (func); t1.join(); cout << "end" << endl; return 0; }

Question Answer

It seems that you are trying to use C++11 threads. If it is true, then

correct #include and #include , i.e. do not use ” in these lines and add # in front of them.
compile with g++ -std=c++11 q.cpp -lpthread (dependency order matters for newer g++)

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

You may also like...

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.