Linux下undefined reference to ‘pthread_create’问题解决

在试用Linux 线程模块时,试用pthread_create 函数。

编译命令为 gcc main.c -o test时,会出现如下错误

/tmp/ccIvH3bU.o: In function `main':
main.c:(.text+0x81): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status

问题的原因:pthread不是linux下的默认的库,也就是在链接的时候,无法找到phread库中哥函数的入口地址,于是链接会失败。

解决:在gcc编译的时候,附加要加 -lpthread参数即可解决。

试用如下命令即可编译通过

gcc main.c -o test -lpthread

#include <unistd.h>
#include <pthread.h> #define NUM 10
int count; void* thread_func(void *arg)
{
count++;
printf("count %d\n", count);
return;
} int main()
{
pthread_t tid[NUM];
int i = 0; for (i = 0; i < NUM; i++)
{
pthread_create(&tid[i], NULL, thread_func, NULL);
} sleep(1); return 0;
}

Linux下undefined reference to ‘pthread_create’问题解决的更多相关文章

  1. Linux下undefined reference to ‘pthread_create’问题解决 zz

    接触了Linux系统编程中的线程编程模块,可gcc sample.c(习惯把书上的sample代码写进sample.c文件中)出现“undefined reference to ‘pthread_cr ...

  2. [Linux] Linux下undefined reference to ‘pthread_create’问题解决

    问题的原因:pthread不是Linux下的默认的库,也就是在链接的时候,无法找到phread库中函数的入口地址,于是链接会失败. 解决:在gcc编译的时候,附加要加 -lpthread参数即可解决.

  3. Debian下undefined reference to ‘pthread_create’问题解决

    今天在写线程测试程序(pthread_create)时出现如下问题, 明明在头文件中包含了<pthread.h>,但是仍然提示找不到函数 pthread_create 和 pthread_ ...

  4. Linux下编译出现undefined reference to ‘pthread_create’问题解决

    1.代码 /* * File: HeartPackageSendAgent.cpp * Author: Pangxiaojian * * * 主要实现:向服务器发送心跳包,每5s向服务器发送一个心跳包 ...

  5. undefined reference to `pthread_create'问题解决

    在编译pthread有关的程序时,出现undefined reference to `pthread_create'这样的错误. 问题原因: pthread 库不是 Linux 系统默认的库,连接时需 ...

  6. undefined reference to 'pthread_create'问题解决 -- 转

    文章出处:http://blog.csdn.net/llqkk/article/details/2854558 由于是Linux新手,所以现在才开始接触线程编程,照着GUN/Linux编程指南中的一个 ...

  7. undefined reference to 'pthread_create'问题解决(转载)

    转自:http://blog.csdn.net/llqkk/article/details/2854558 由于是Linux新手,所以现在才开始接触线程编程,照着GUN/Linux编程指南中的一个例子 ...

  8. 在linux下编译线程程序undefined reference to `pthread_create'

    由于是Linux新手,所以现在才开始接触线程编程,照着GUN/Linux编程指南中的一个例子输入编译,结果出现如下错误:undefined reference to 'pthread_create'u ...

  9. Linux Ubuntu运行线程程序出现undefined reference to ‘pthread_create’和undefined reference to ‘pthread_join’错误。

    Linux Ubuntu运行线程程序出现undefined reference to ‘pthread_create’和undefined reference to ‘pthread_join’错误. ...

随机推荐

  1. 利用AD采集获取外部温度传感器的值

    #include "led.h" #include "delay.h" #include "key.h" #include "sy ...

  2. swift UILabel多行显示时 计算UILable的高度(可用于UILable高度自适应)

    代码如下 func heightForView(text:String, font:UIFont, width:CGFloat) -> CGFloat{ let label:UILabel = ...

  3. hdu--1026--Ignatius and the Princess I(bfs搜索+dfs(打印路径))

    Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  4. Java 运行期数据区

    对于 Java 开发者来说,由虚拟机进行内存管理是把双刃剑,一方面免去了繁杂的内存管理工作,另一方面,一旦出现内存泄漏和溢出方面的问题,如果不了解虚拟机是怎样使用内存的,排查问题将成为一项艰难的工作. ...

  5. Handler案例-简易打地鼠游戏(延时处理消息)

    1. 游戏思路 (1)用ImageView显示地鼠,初始状态将ImageView设置为不可见状态.当开始游戏后,通过sendMessageDelayed()方法延时发送消息,使ImageView显示出 ...

  6. 自制刻度尺-前端简易实现"腾讯信用"界面

    依据我现有的知识,在前端上"简易"的实现了腾讯信用的界面,同时自己自制了一个竖直的刻度尺插件,曲线的位置可以根据传入的数值动态的改变,这次主要也想总结一下关于jQuery中exte ...

  7. absolute 的containing block( 容器块)计算方式跟正常流有什么不同?

    无论属于哪种,都要先找到其祖先元素中最近的 position 值不为 static 的元素,然后再判断:1.若此元素为 inline 元素,则 containing block 为能够包含这个元素生成 ...

  8. 运用经典方法进行横截面数据分类 笔记 (基于R)

    参考资料: [1]吴喜之. 复杂数据统计方法[M]. 中国人民大学出版社, 2015. 一.logistic回归与probit回归 logistic回归和probit回归都属于广义线性模型. 广义线性 ...

  9. shell 编程之函数

    shell 函数的定义和普通的c语言函数定义差不多 function(){ } shell 函数的返回值,可以显示的return 语句,如果没有return  那么就会把最后一条语句的执行结果作为返回 ...

  10. MySQL连接问题【mysql_connect和mysql_pconnect区别】

    --MySQL连接问题[mysql_connect和mysql_pconnect区别] -------------------------------------------------------- ...