Pthread library undefined link

I use eclipse for Fedora 17 (with GCC), and I have an undefined link to pthread_create (), even if pthread.h is enabled, and if I have -lpthread on the gcc build command line ...

Here is my code, just in case

void* repair()
{
    int var;
    for ( var = 0; var < NB_ITER ; var += 2 )
    {
        printf( "PAIR : %d\n", var );
    }

return NULL;
} // pair

void exo03()
{
    pthread_t id1;
    pthread_create(&id1, NULL, &repair, NULL);
}

Thanks for the help:)

+5
source share
2 answers

On linux, FreeBSD (and some other * nix variants) you should use the compiler option -pthreadand not try to link to the pthread library.

For eclipse :

Eclipse is not configured to host the -pthread argument in the gcc compilation. To solve this problem, go to the menu:

Project β†’ Properties

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

Add the "-pthread" argument to the top of the "Other flags"

:

c/++ build β†’ β†’ GCC C Linker β†’

"pthread" . "" . Pthreads .

man gcc:

-pthread: pthreads. , .

:

GCC -pthread (aka -pthreads) //, Posix. // Posix ( Posix ), libpthread

-lpthread libpthread, -lm libm. -lpthread libpthread, Posix thread, .

+8

libpthread?

$> gcc ... -lpthread
+4

All Articles