问题描述:hero@ubuntu:~/WORK/for_xc7z035/app/sdr_7010$ gcc -o ./test ./test.c
/tmp/cc7BcXdf.o: In function `main':
test.c:(.text+0x1d7): undefined reference to `pthread_create'
test.c:(.text+0x1fb): undefined reference to `pthread_create'
test.c:(.text+0x21f): undefined reference to `pthread_create'
test.c:(.text+0x233): undefined reference to `pthread_join'
test.c:(.text+0x247): undefined reference to `pthread_join'
test.c:(.text+0x267): undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
问题原因:
1, pthread 库不是 Linux 系统默认的库,在编译多线程程序时,需要在编译命令中添加链接libpthread.a库。
2,忘了加上头文件#include<pthread.h>
问题解决:
在编译中要加 -lpthread参数
gcc ./test.c -o ./test -lpthread
本文解决了一个在使用GCC编译多线程程序时遇到的未定义符号引用错误,具体为找不到pthread库中的函数。问题在于编译时未正确链接pthread库及可能遗漏了必要的头文件。
3421

被折叠的 条评论
为什么被折叠?



