G ++ 4.8.1 C ++ Threads, std :: system_error - operation not allowed?

This is not a duplicate question, because the solutions presented do not work on my compiler. I am trying to compile and run the following example from this question .

#include <thread> #include <iostream> int main(int, char **){ std::thread tt([](){ std::cout<<"Thread!"<<std::endl; }); tt.join(); } 

I tried to use the solutions presented both in this original question and in the accepted answer to this duplicate . However, although I tried all the combinations listed above and, in particular, tried

 g++ main.cpp -o main.out -pthread -std=c++11 

When I run the resulting executable, I still get

 terminate called after throwing an instance of 'std::system_error' what(): Enable multithreading to use std::thread: Operation not permitted Aborted (core dumped) 

Here is the result of g++ --version .

 g++ (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 Copyright (C) 2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 

Is there a different order or set of commands that I need to use for g++ 4.8.1 ?

+6
source share
1 answer

this was answered here

 g++ -Wl,--no-as-needed -std=c++11 -pthread main.cpp -o main.out 
+10
source

All Articles