Pthreads and Eclipse IDE

Have you come across a situation where a C/C++ project that uses Pthread API fails to compile via the Eclipse IDE?

If your answer to the above question is ‘YES’, then this post is for you.

The CDT plugin in the Eclipse IDE is not configured to add the -pthread argument when the user tries to compile a C/C++ project. Please follow the steps listed below to successfully compile a C/C++ project which uses Pthread library in Eclipse.

  • Open Eclipse (it is assumed that CDT plugin is installed).
  • On the menu bar, choose Projects->Properties.
  • From the bar on the left, choose c/c++ build –> GCC C Compiler –> Miscellaneous.
  • Add the -pthread argument into the beginning of the Other Flags.
  • Choose c/c++ build–>Settings->GCC C Linker->Libraries and include the pthread library into the other libraries.
  • Click Apply and rebuild the project. Pthreads should work now.