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点点 创作,采用 知识共享 署名-非商业性使用-相同方式共享 3.0 中国大陆 许可协议进行许可。欢迎转载,请注明出处:
转载自:cococo点点 http://www.cnblogs.com/coder2012


相关文章
|
10月前
|
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
102 0
undefined reference to symbol XGetWindowAttributes/cairo_destroy/XShapeGetRectangles
undefined reference to symbol XGetWindowAttributes/cairo_destroy/XShapeGetRectangles
106 0
Looking for pthread_create - not found
Looking for pthread_create - not found
113 0
undefined reference to `swr_init+
undefined reference to `swr_init+
90 0
|
C++
undefined reference to `vtable for XXX‘
undefined reference to `vtable for XXX‘
120 0
解决办法:undefined reference to symbol 'pthread_mutexattr_settype@@GLIBC_2.2.5'
解决办法:undefined reference to symbol 'pthread_mutexattr_settype@@GLIBC_2.2.5'
208 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
|
Linux C语言
gcc编译出现 undefined reference to ‘pthread_create‘ 的解决方法
gcc编译出现 undefined reference to ‘pthread_create‘ 的解决方法
193 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
762 0