Home > Article > Backend Development > Why Does g Throw \"Enable multithreading to use std::thread: Operation not permitted\" and How to Fix It?
Compiling Multithreaded Code with g : Troubleshooting and Implementing a Workaround
Despite including the necessary -pthread flag for linking against the POSIX threads library, you may encounter an error when compiling multithreaded code with g . The error message "Enable multithreading to use std::thread: Operation not permitted" indicates that multithreading capability is disabled in your current configuration.
To address this issue, a workaround proposed in a relevant bug discussion involves adding the -Wl,--no-as-needed flag to your compilation command. This flag instructs the linker to not perform automatic dependency resolution, which can help resolve the conflict with the system-provided POSIX threads library:
g++ main.cpp -o main.out -pthread -std=c++11 -Wl,--no-as-needed
By implementing this workaround, you should be able to successfully compile and run your multithreaded code using g .
The above is the detailed content of Why Does g Throw \"Enable multithreading to use std::thread: Operation not permitted\" and How to Fix It?. For more information, please follow other related articles on the PHP Chinese website!