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. 读书笔记(一)—— 浅析浏览器渲染过程和html中的文件加载

    在构建页面时,我们会在html中载入一个或多个css和js文件.或许大家都已经习惯了"最佳实践"中,css文件应该放在<head>标签中引入,而js文件则是放在< ...

  2. 移动端https抓包那些事--进阶篇

    上一次和大家介绍了手机端https抓包的初级篇,即在手机未root或者未越狱的情况下如何抓取https流量,但是当时分析应用时会发现,好多应用的https的流量还是无法抓取到,这是为什么呢? 主要原因 ...

  3. Hbase集群监控

    Hbase集群监控 Hbase Jmx监控 监控每个regionServer的总请求数,readRequestsCount,writeRequestCount,region分裂,region合并,St ...

  4. Asp.net中,从弹出窗体取选择值(转)

    在Asp.net中,从A页面中弹出B页面,在B页面中选择数据后,关闭并将数据更新到A页面,是一种常用 的方式.只是我对Javascript不熟悉,所以捣鼓了一下午,终于有了一点成绩:测试项目有两个页面 ...

  5. centos 系统常用命令

    一:查看cpu信息more /proc/cpuinfo | grep "model name" grep "model name" /proc/cpuinfo ...

  6. HTML 基本标签02

    02-html基本标签 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> & ...

  7. iOS 折线图实现

    图表绘制的过程实际上是坐标位置的计算过程,至于画线只要有了position,通过CAShapeLayer+BezierPath很快就可以画出来,这里提供一个绘制折线的demo,贵在思路,有需要的可以参 ...

  8. BOM部分笔记整理

    BOM部分整理 (章节 8.9) 概览: 一.介绍BOM 在web中,JS的核心对象就是BOM. 1.1 在浏览器中,window对象 == global 所以,你在全局环境下定义的变量,函数都会自动 ...

  9. 初探 spring data(一)--- spring data 概述

    由于自己一个项目要用多到Sql与NoSql两种截然不同的数据结构,但在编程上我希望统一接口API,让不同类型的数据库能在相同的编程接口模式下运作.于是找了一个spring的官网,发现一个spring ...

  10. 剑指OFFER(百度笔试)——二叉树的子结构

    百度软件开发实习生笔试: 1.模拟短作业优先调度算法,计算平均等待时间,例如输入[0,2,4,8]表示四个作业分别是第0s到.第2s到.第4s到.第8s到.[2,1,6,3]表示四个作业的运行时间. ...