undefined reference to 'pthread_create'

Linux下编写线程函数的时候,虽然你已经把头文件

#include<pthread.h>

加入,但是会提示

thread_date.c:(.text+0x67): undefined reference to `pthread_create'
thread_date.c:(.text+0xaa): undefined reference to `pthread_join'

编译失败。

 

失败原因:

 pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a,所以在使用pthread_create()创建线程,以及调用 pthread_atfork()函数建立fork处理程序时,需要链接该库。

解决方法:

 #在编译中要加 -lpthread参数
 gcc thread.c -o thread -lpthread

 

posted @ 2013-03-31 15:26  cococo点点  阅读(484)  评论(0编辑  收藏  举报