The error
I am trying to use std::thread but I have this error when I try to run it.
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
Aborted (core dumped)
Result of my research
There are a lot of questions about it and every answer say similar things : I have to build with "-pthread" or "-lpthread". Some also say to add "-Wl,--no-as-needed".
Link Link Link Link Link Link Link
I tried a lot of things but none worked.
Details
I am compiling with Code::Blocks 12.11, GNU GCC Compiler on Lubuntu. In the compiler settings menu, compiler flags I have checked
"Have g++ follow the C++11 ISO C++ language standard [-std=c++11]"
and under other options I wrote what the answer was saying, here is an example
-pthread
-Wl,--no-as-needed
Here is the build log I have (I am not sure if it is important)
g++ -Wall -fexceptions -std=c++11 -g -pthread -Wl,--no-as-needed -std=c++11 -I../DeskManagerDll -I/usr/include/X11/extensions -I/usr/include/X11 -c /home/julien/Documents/test/main.cpp -o obj/Debug/main.o
g++ -L/home/julien/Documents/DeskManagerDll -L-L/usr/lib/i386-linux-gnu -o bin/Debug/test obj/Debug/main.o -L/usr/X11R6/lib -lX11 -lXext -lpthread -Wl,--no-as-needed /home/julien/Documents/DeskManagerDll/bin/Debug/libDeskManagerDll.so
Output size is 187,15 KB
My question
What am I doing wrong ? What did I miss ?
Edit
I made a very simple program to exclude any other problem.
#include <thread>
void test()
{
}
int main()
{
std::thread thread_fct (test);
return 0;
}
The build log with this program:
g++ -Wall -fexceptions -std=c++11 -g -pthread -Wl,--no-as-needed -std=c++11 -c /home/julien/Documents/test/main.cpp -o obj/Debug/main.o
g++ -o bin/Debug/test obj/Debug/main.o
I still have the exact same error. I really don't know what to try. Do you have any idea ?