Home >Backend Development >C++ >Why Does My `std::thread` Code Fail with \'Operation not permitted\'?
Linking Options for std::thread in GCC/Linux
When attempting to use std::thread with G , as exemplified by the test code provided in the inquiry, a common error encountered is the "Operation not permitted" system error. This is often due to the omission of the correct linking options when compiling the code.
To address this issue, it is necessary to specify the -pthread compiler option which instructs the linker to include the necessary pthread library, as this library is used to implement std::thread on Linux systems.
However, it is crucial to ensure that the -pthread option is placed after the source files when invoking the compiler, as shown below:
$ g++ -std=c++0x test.cpp -pthread
By following this approach, you can successfully compile and run your code that utilizes std::thread.
The above is the detailed content of Why Does My `std::thread` Code Fail with \'Operation not permitted\'?. For more information, please follow other related articles on the PHP Chinese website!