今天学习UNIX环境高级编程第11章中的线程编程,在编译第一个demo时,出现了“undefined reference to ‘pthread_create’”这种错误导致无法编译通过。
问题的原因:pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a,所以在使用pthread_create()创建线程,以及调用 pthread_atfork()函数建立fork处理程序时,需要链接该库。
解决:在gcc编译的时候,命令加上 -lpthread参数即可解决。
程序11-1.c
#include "apue.h"
#include <pthread.h>
pthread_t ntid;
static void pr

在学习UNIX环境高级编程的线程章节时,遇到编译错误'undefined reference to 'pthread_create''。原因是pthread库未被默认链接。解决方法是在gcc编译时添加-lpthread参数,链接libpthread.a库。
最低0.47元/天 解锁文章
4044

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



