c – Undefined reference to pthread_create in Linux

c – Undefined reference to pthread_create in Linux

For Linux the correct command is:

gcc -pthread -o term term.c

In general, libraries should follow sources and objects on command line, and -lpthread is not an option, its a library specification. On a system with only libpthread.a installed,

gcc -lpthread ...

will fail to link.

For Linux the correct command is:

gcc -o term term.c -lpthread
  1. you have to put -lpthread just after the compile command,this command will tell to the compiler to execute program with pthread.h library.
  2. gcc -l links with a library file.Link -l with library name without the lib prefix.

c – Undefined reference to pthread_create in Linux

in eclipse

properties->c/c++Build->setting->GCC C++ linker->libraries in top part add pthread

Leave a Reply

Your email address will not be published.