Solution for undefined reference to 'pthread_create'

  • 2020-05-06 12:11:14
  • OfStack

Following an example in the GUN/Linux programming guide, the following error occurs:

undefined reference to 'pthread_create'
undefined reference to 'pthread_join'

Reason for the problem:
The       pthread library is not the default library of the Linux system, and you need to use the static library libpthread.a to connect, so you need to link this library when you create a thread using pthread_create() and create an fork handler by calling the pthread_atfork() function.

Problem solved:
      is compiled with the -lpthread parameter
      gcc thread.c -o thread -lpthread
      thread.c is your source file. Don't forget to add the header #include< pthread.h >


Related articles: