在写linux线程时,遇到一下错误:
arm-linux-gcc -Wall -o "main" "main.c"
/tmp/ccqHoSrP.o: In function `main':main.c:(.text+0x2f0): undefined reference to `pthread_create'
main.c:(.text+0x330): undefined reference to `pthread_create'
main.c:(.text+0x368): undefined reference to `pthread_join'
main.c:(.text+0x398): undefined reference to `pthread_join'
collect2: ld returned 1 exit status
编译失败。
根据错误提示,#include <pthread.h> 头文件没有编译。检查了程序没有问题。
原因:pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a,
方法:在makefile文件中加入 -lpthread
arm-linux-gcc -o main $(objects) -lpthread
再次编译没有错误,程序运行正常。