C ++ 11 not working

My programs look below

#include <iostream> #include <thread> #include <exception> void hello() { std::cout << "Hello world!!!!" << std::endl; } int main() { std::cout << "In Main\n"; std::thread t(hello); t.join(); return 0; } 

When I compile it with the following command, I get no errors

  g ++ - 4.7 -std = c ++ 11 main.cpp 

But when I run it, I get the following error

  In main
 terminate called after throwing an instance of 'std :: system_error'
 what (): Operation not permitted
 Aborted (core dumped)

Can someone help me with where I'm wrong?

+7
source share
5 answers

When I use C ++ 11 streams with GCC, I use:

 g++ -std=c++0x -pthread -g main.cpp 

This works for me.

+10
source

When compiling code with g++ use the -pthread .

The following is the answer I found from stackoverflow: Does g ++ have a C ++ 11 thread model using pthreads in the background?

+6
source

Everyone has already answered that you need the -pthread argument passed to the compiler. This will almost certainly not change in 4.8, but according to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52681 the exception will at least have a nice message about what's wrong.

+3
source

You may need a link to the pthread library

0
source

You can try,

 g++ --std=c++11 -lpthread main.cpp 
0
source

All Articles