Adding -pthread to eclipse, for using posix threads

15/02/2009

Problem

Cannot compile c/c++ project with -pthread. Eclipse is complaining about things.

Solution

Eclipse is not configured to put the -pthread argument in the gcc compilation. To solve this, go to the Menu:

Project -> Properties

From the bar on the left:

c/c++ build -> GCC C Compiler -> Miscellaneous

Add the “-pthread” argument into the beginning of the “Other Flags” Also go to:

c/c++ build -> Settings -> GCC C Linker -> Libraries

And include the “pthread”library into the other libraries. Click Apply and rebuild the project. Pthreads must work now.

There are 31 comments in this article:

  1. 23/02/2009ahmet say:

    thanks

  2. 10/04/2009rajend say:

    this one helped me too…
    thanks a lot

  3. 4/07/2009fork() a child say:

    it helped me too… thanks!

  4. 28/10/2009alex say:

    +1

  5. 21/11/2009nuno say:

    thanks a lot:D

  6. 6/01/2010vinod say:

    Thanks dude, yu rock…

    V…

  7. 23/02/2010aaron say:

    Thank you.

  8. 5/03/2010alex say:

    thanks a lot..

  9. 15/04/2010dahdash say:

    tnx ;)

  10. 17/10/2010donat3llo say:

    thanks a bunch bro, works like a charm for me.

  11. 21/11/2010david say:

    thank you very mutch god bless you

  12. 23/11/2010Gluko say:

    Thanks!!! very helpful

  13. 23/02/2011Fred say:

    Thanks!

  14. 29/04/2011Dolcezeus say:

    don’t work for me.. i have an linker error the option is present on compiler but not on Linker console outpt.. please help me, if i compile manually the program work fine, but in eclipse i can’t buid it.

  15. 1/05/2011desufag say:

    Thank you, really helped.

  16. 9/06/2011Abraham say:

    Does anyone know how to debug pthreads in eclipse? I tried using breakpoints but I never hit them; however the console output tells me the code is indeed running and outputting correctly.

  17. 14/06/2011Roy say:

    Thank you ..really helped

  18. 18/09/2011cash say:

    thank a lot :)

  19. 2/10/2011some dude say:

    awesome simple fix. thanks

  20. 26/10/2011Cem say:

    thanks my brother, it has worked but i didnt understand why we had to do this configuration

  21. 6/11/2011Hashim Ali say:

    Hello!
    Thanks for the post.
    I have one question, What do you think if I have requirement of non-blocking thread kind of functionality but not using threads?
    Many thanks for help.

  22. 23/11/2011Donald say:

    don’t work for me.Build the project, the console give me such messages:

    D:/NEAT/include/neat/ctrl/../win32/pthread.h:1212: error: expected constructor, destructor, or type conversion before “pthread_getw32threadhandle_np”
    D:/NEAT/include/neat/ctrl/../win32/pthread.h:1230: error: variable `pthreadCancelableWait’ definition is marked dllimport.
    D:/NEAT/include/neat/ctrl/../win32/pthread.h:1230: warning: `__cdecl__’ attribute only applies to function types
    D:/NEAT/include/neat/ctrl/../win32/pthread.h:1230: error: `HANDLE’ was not declared in this scope
    D:/NEAT/include/neat/ctrl/../win32/pthread.h:1231: error: variable `pthreadCancelableTimedWait’ definition is marked dllimport.
    D:/NEAT/include/neat/ctrl/../win32/pthread.h:1231: warning: `__cdecl__’ attribute only applies to function types
    D:/NEAT/include/neat/ctrl/../win32/pthread.h:1231: error: `HANDLE’ was not declared in this scope
    D:/NEAT/include/neat/ctrl/../win32/pthread.h:1232: error: `DWORD’ was not declared in this scope
    D:/NEAT/include/neat/ctrl/../win32/pthread.h:1232: error: initializer expression list treated as compound expression
    D:/NEAT/include/neat/ctrl/../win32/pthread.h:1311: error: expected constructor, destructor, or type conversion before “ptw32_get_exception_services_code”

    Could anyone help me ?
    thanks in advance!

  23. 18/01/2012kyle say:

    thanks a ton. this helped

  24. 19/03/2012Become Casino Affiliates Extra $500 for 5 approved players in first 60 days say:

    I’m gone to tell my little brother, that he should also pay a visit this weblog on regular basis to take updated from newest information.

  25. 22/06/2012elvis say:

    WOW tnx!!!

  26. 27/07/2012Scott Tucker CBS say:

    Hey there! I could have sworn I’ve been to this site before but after reading through some of the post I realized it’s new to me.
    Nonetheless, I’m definitely delighted I found it and I’ll be
    book-marking and checking back frequently!

  27. 14/08/2012Antonio say:

    It works! Great help! It works for TinyThread++

  28. 23/08/2012My Site say:

    Hello there, You have done a great job.
    I will definitely digg it and personally suggest to my friends.
    I am confident they’ll be benefited from this web site.

  29. 9/10/2012Andy say:

    Wow this caused me a lot of headaches, thanks a ton friend!

  30. 7/12/2012Łukasz say:

    Thanks for help :)

  31. 8/02/2013manoj say:

    Thanks.. it helped..

Write a comment: