The solution for undefined reference to 'pthread_create'

  • 2020-05-09 19:39:47
  • OfStack

Follow an example from the GUN/Linux programming guide and type in the following error:

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

Reasons for the problem:
The       pthread library is not the default library of the Linux system. The static library libpthread.a needs to be used when connecting, so you need to link this library when creating threads using pthread_create() and when creating fork handlers by calling the pthread_atfork() function.

Problem solving:
      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: