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
Similar Posts:
- Hi3516DV300 Chip Error: “undefined reference to ×”
- invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’
- The source code installs the git tool, which shows /usr/local/lib64/libcrypto.a(dso_dlfcn.o) undefined reference to `dlopen’
- gcc undefined reference to sqrt
- Using SQLite to show undefined reference to ` SQLite3_ open’…
- Undefined reference to ` SEM appears when compiling with tcmalloc_ init’
- No matching function call to ‘pthread_create’ [How to Solve]
- undefined symbol: xxx – undefined reference to `typeinfo
- GCC refers to math. H header file, and there are some errors such as undefined reference to ` POW ‘when compiling