C++ 11 tip of the day

If you’re working with code using C++11 ‘s use of the <thread> library, and you get this error at runtime:

 terminate called after throwing an instance of 'std::system_error'
  what():  Operation not permitted
zsh: abort      ./main
 

That means you forgot to tell g++ to link to the pthread library when you compiled. Add the flag

 -lpthread 

to your g++ command string, and you should be set to go.

I’ve run into this error a few times already, and I haven’t found a good google search that answers it, so I decided to write this one. Hope it absolves a few head-scratchers out there….

This entry was posted in Coding, Open Source. Bookmark the permalink.

One Response to C++ 11 tip of the day

  1. Shengliang says:

    Thanks for sharing this. But it seems that -pthread is the right way to go