在编译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

undefined reference to `pthread_create'问题解决的更多相关文章

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

    Linux下undefined reference to 'pthread_create'问题解决 在试用Linux 线程模块时,试用pthread_create 函数. 编译命令为 gcc main ...

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  9. 解决错误---undefined reference to `pthread_create‘

    今天试着敲了一下APUE的小例子,遇到了个错误 -----  undefined reference to `pthread_create.(为自己这么晚接触多线程惭愧). 上网上查了一下,借人经验. ...

随机推荐

  1. Altium Designer /DXP无网络铺铜:

    有的设计者在PCB加工的时候会删除网络以便为了保护.但如果后续在无网络PCB上进行修改时就不叫麻烦,没有网络连铺铜都无法进行.一般手动添加网络只对要铺铜的地网络进行,其它的要修改者自己确保版图的正确性 ...

  2. laravel查询构造器中别名的问题

    Laravel框架对数据库的封装是比较完善的,用起来也比较方便.但之前有一个问题一直困扰着我,就是利用laravel作查询时.如果想给表名或是字段名起别名是比较麻烦的事.但翻阅它的文档不难发现,它提供 ...

  3. powerdesigner中将表的name在生成建表sql时生成注释

    1.为powerdesigner的表设置注释方法: powerdesigner默认没有注释: 设置方法: 选择那个表 右键- >Properties- >Columns- >Cust ...

  4. Xcode 的正确打开方式——Debugging(转载)

    Xcode 的正确打开方式——Debugging   程序员日常开发中有大量时间都会花费在 debug 上,从事 iOS 开发不可避免地需要使用 Xcode.这篇博客就主要介绍了 Xcode 中几种能 ...

  5. How to push your code in git

    1. display all the branches git branch -a 2. delete branches git br -d <branch> # 删除某个分支 git b ...

  6. Java线程新特性--- Lock

    在Java5中,专门提供了锁对象,利用锁可以方便的实现资源的封锁,用来控制对竞争资源并发访问的控制,这些内容主要集中在java.util.concurrent.locks包下面,里面有三个重要的接口C ...

  7. HttpClient和WebService的区别和介绍

    1. HTTP 协议可能是现在 Internet 上使用得最多.最重要的协议了,越来越多的 Java 应用程序需要直接通过 HTTP 协议来访问网络资源.  HttpClient用来调用服务,它是模拟 ...

  8. rbenv安装ruby2.3.0在线安装不上。老子出绝招了(更新)

    今天把系统换成Linux mint了.感觉比ubuntu的好用太多,细节真是不错,Ubuntu感觉就是毛坯房,Linux mint真是精装修啊 问题来了.安装rbenv后,然后安装rbenv-buil ...

  9. asterisk中eyebeam与移动的IMS帐号对接

    账号和密码: 05128068****       xbfldz6658****IP:120.195.9.148域名:ims.js.chinamobile.com    上图吧:

  10. 去掉 input type="number" 右边图标

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...