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.

The URI to TrackBack this entry is: https://sks8.wordpress.com/2009/08/19/pthreads-and-eclipse/trackback/

RSS feed for comments on this post.

10 CommentsLeave a comment

  1. THAAAAAAAAAAAAAAAAAAAAAAANKS ALOT! God Bless You! 😀

  2. I’m getting the next error on compilation time:

    cannot find -lpthread

    on Eclipse, please help me 😦

    • same here. It does not work

  3. I am university student in the Brazil.
    Your initiative has very good.

    Thanks !!!

  4. God blesssssss!!!! thanks a lot, saved my life =)

  5. thanks a lot,,
    it works,.
    thanks thanks thanks

    regards

  6. OH YOU BEAUTIFUL PERSON, IT WORKS, OH IT WORKS, OH GOOD GOD THANK YOU.

  7. Thank you!

  8. Do you guys know how to debug the pthreads in eclipse?
    I call pthread_create and I know the code is running as it’s outputting properly; however, I need to debug as I believe there are some errors in it. Any idea?

  9. thank you very very much! 🙂


Leave a Reply to Doaa Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: