Compile this file:
//Create a C++11 thread from the main program
//This function will be called from a thread
std::cout << "Hello, from thread! " << std::endl;
std::cout << "Hello, from main! " << std::endl;
//Launch a thread
//Join the thread with the main thread
Hello, from main!
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
Aborted (core dumped)
Process returned 134 (0x86) execution time : 0.110 s
Press ENTER to continue.
g++: error: unrecognized command line option ‘-Wl’
g++: error: unrecognized command line option ‘--no-as-needed’
If you compile with -pthread you should link with -lpthread.
The second is easy, it must be:
-Wl,--no-as-needed (',' is missing), but it is used for the linker. Your call only compiles into an object file, so you can erase that.
Another note on the second one, it might be that you actually have to link with
-Wl,--no-as-needed due to a bug in some gcc version
As for Code::Blocks, you can add
-Wl,--no-as-needed and -lpthread in the linker tab of the build options.