您的位置:首页 > Web前端

thread_join.c:(.text+0x6f): undefined reference to `pthread_create' 问题的解决

2012-05-10 20:04 716 查看
今天在测试一个线程例子时,结果出现如下错误

[root@tom fzf]# gcc thread_join.c -o thread_join

/tmp/cc1HozRv.o: In function `main':

thread_join.c:(.text+0x6f): undefined reference to `pthread_create'

thread_join.c:(.text+0x91): undefined reference to `pthread_join'

collect2: ld returned 1 exit status

问题原因:

pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a。

所以在使用pthread_create()创建线程,pthread_join()线程等待,以及调用 pthread_atfork()函数建立fork处理程序时,需要链接该库。
问题解决如下:

在编译中要加 -lpthread参数

[root@tom fzf]# gcc thread_join.c -o thread_join -lpthread
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: