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:

[code lang=”bash”] 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

[code lang=”bash”] -lpthread [/code]

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.

2 Responses 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

  2. Javi says:

    Thanks a lot

Leave a Reply

Your email address will not be published. Required fields are marked *