Thread doesn’t work with an error: Enable multithreading to use std::thread: Operation not permitted

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

  1. correct #include <thread> and #include <iostream>, i.e. do not use " in these lines and add # in front of them.
  2. 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

Leave a Comment