undefined reference to `pthread_create'问题解决

在编译pthread有关的程序时,出现undefined reference to `pthread_create'这样的错误。

 

问题原因:

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

 

问题解决:

方法一:

在编译中要加 -lpthread参数
gcc thread.c -o thread -lpthread
thread.c是写的源程序,不要忘了加上头文件#include<pthread.h>

 

方法二:

编译时加-lrt参数

gcc thread.c -o thread -lrt

 

参考:

http://blog.csdn.net/llqkk/article/details/2854558

http://bbs.chinaunix.net/thread-1586752-1-1.html

posted @ 2016-06-05 23:43  0dmin'blog  阅读(3004)  评论(0编辑  收藏  举报
TOP