I am compiling a multithreaded library using eclipse.
How can i add the -pthread or -pthreads option to the call made to g++ by eclipse?
-pthread Adds support for multithreading with the pthreads library. This option sets flags for both the preprocessor and linker.
The pthreads run time library usually lives in /lib, while the development library usually lives in /usr/lib.
The original answer that I wrote almost 2 years ago is now outdated; here is how to do it today.
Either right click on the project folder or File > Properties, then C/C++ Build > Settings. At the GCC C++ Linker > Linker flags add -pthread
and finally hit the Apply button. That's all.
I have tested this with gcc 4.8 and Eclipse Luna on Ubuntu 14.04. Thank to Neil Traft for pointing it out in a comment.
The original answer from February 2014, now outdated:
Either right click on the project folder or File > Properties, then C/C++ Build > Settings.
At the GCC C++ Compiler > Miscellaneous add -pthread
to Other flags and hit the Apply button.
At the GCC C++ Linker > Libraries click the icon with the green plus sign on the Libraries bar to add pthread
and finally hit the Apply button.
This must solve it.
Note that you have to tell both the compiler and the linker that you are compiling a multi-threaded application (passing -pthread
to the compiler and -lpthread
to the linker).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With