Home >Backend Development >C++ >Why Does g Still Throw \'Enable Multithreading to use std::thread: Operation not permitted\' Even With -pthread Flag?
Compiling Multithread Code with g
An individual encountered difficulty compiling multithread code using g , despite specifying the necessary flags. The code, which includes header files for I/O and thread manipulation, was straightforward, containing a worker thread and a main thread. However, the compilation attempt resulted in an error:
terminate called after throwing an instance of 'std::system_error' what(): Enable multithreading to use std::thread: Operation not permitted Aborted (core dumped)
The individual had already included the -pthread flag in their compilation command, which is typically recommended to enable multithreading in g . However, the issue persisted.
The answer to the problem stems from a bug in gcc. The workaround suggested in the last comment of the relevant bug discussion involves adding the following flag to the compilation command:
-Wl,--no-as-needed
By implementing this workaround, the individual was able to successfully compile and run their multithread code using g .
The above is the detailed content of Why Does g Still Throw \'Enable Multithreading to use std::thread: Operation not permitted\' Even With -pthread Flag?. For more information, please follow other related articles on the PHP Chinese website!