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

 本文转自cococo点点博客园博客,原文链接:http://www.cnblogs.com/coder2012/archive/2013/03/31/2991789.html,如需转载请自行联系原作者

相关文章
|
Ubuntu C语言
【ubuntu】2.c:(.text+0xd2): undefined reference to `pthread_create‘ collect2: error: ld returned
【ubuntu】2.c:(.text+0xd2): undefined reference to `pthread_create‘ collect2: error: ld returned
144 0
undefined reference to symbol XGetWindowAttributes/cairo_destroy/XShapeGetRectangles
undefined reference to symbol XGetWindowAttributes/cairo_destroy/XShapeGetRectangles
139 0
Looking for pthread_create - not found
Looking for pthread_create - not found
155 0
undefined reference to `swr_init+
undefined reference to `swr_init+
111 0
在main函数中创建新对象时出错 No enclosing instance of type ooo is accessible. Must qualify the allocation with a
在main函数中创建新对象时出错 No enclosing instance of type ooo is accessible. Must qualify the allocation with a
在main函数中创建新对象时出错 No enclosing instance of type ooo is accessible. Must qualify the allocation with a
解决办法:undefined reference to symbol 'pthread_mutexattr_settype@@GLIBC_2.2.5'
解决办法:undefined reference to symbol 'pthread_mutexattr_settype@@GLIBC_2.2.5'
295 0
|
Linux C语言
gcc编译出现 undefined reference to ‘pthread_create‘ 的解决方法
gcc编译出现 undefined reference to ‘pthread_create‘ 的解决方法
310 0
gcc编译出现 undefined reference to ‘pthread_create‘ 的解决方法
|
程序员 编译器 C语言
解决办法:undefined reference to symbol '_ZTVN10__cxxabiv117__class_type_infoE@@CXXABI_1.3
解决办法:undefined reference to symbol '_ZTVN10__cxxabiv117__class_type_infoE@@CXXABI_1.3
929 0
解决办法:undefined reference to symbol &#39;dlclose@@GLIBC_2.2.5&#39;
解决办法:undefined reference to symbol &#39;dlclose@@GLIBC_2.2.5&#39;
1582 0