Undefined reference to ‘pthread’ appears in Linux Ubuntu running thread program_ Create ‘and undefined reference to’ pthread ‘_ ‘join’ error
Write good thread code, compile
gcc xiancheng.c -o xiancheng
The following prompt appears
1 linux@ubuntu64-vm:~/workdir$ gcc xiancheng.c -o xiancheng
2 /tmp/ccOCxLrd.o: In function `main':
3 xiancheng.c:(.text+0x11e): undefined reference to `pthread_create'
4 xiancheng.c:(.text+0x131): undefined reference to `pthread_join'
5 collect2: ld return 1
6 linux@ubuntu64-vm:~/workdir$
The reason for the problem: the pthread header file is included in the header file reference of the program, and it is not the default library under Linux, that is, when linking, the entry address of the function in the phread library cannot be found, so the link will fail
#include <pthread.h>
Solution: when compiling GCC, add the – lpthread parameter
Compile using the following code
gcc xiancheng.c -o xiancheng -lpthread
You can pass