Linux下undefined reference to ‘pthread_create’问题解决
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’问题解决的更多相关文章
- Linux下undefined reference to ‘pthread_create’问题解决 zz
接触了Linux系统编程中的线程编程模块,可gcc sample.c(习惯把书上的sample代码写进sample.c文件中)出现“undefined reference to ‘pthread_cr ...
- [Linux] Linux下undefined reference to ‘pthread_create’问题解决
问题的原因:pthread不是Linux下的默认的库,也就是在链接的时候,无法找到phread库中函数的入口地址,于是链接会失败. 解决:在gcc编译的时候,附加要加 -lpthread参数即可解决.
- Debian下undefined reference to ‘pthread_create’问题解决
今天在写线程测试程序(pthread_create)时出现如下问题, 明明在头文件中包含了<pthread.h>,但是仍然提示找不到函数 pthread_create 和 pthread_ ...
- Linux下编译出现undefined reference to ‘pthread_create’问题解决
1.代码 /* * File: HeartPackageSendAgent.cpp * Author: Pangxiaojian * * * 主要实现:向服务器发送心跳包,每5s向服务器发送一个心跳包 ...
- undefined reference to `pthread_create'问题解决
在编译pthread有关的程序时,出现undefined reference to `pthread_create'这样的错误. 问题原因: pthread 库不是 Linux 系统默认的库,连接时需 ...
- undefined reference to 'pthread_create'问题解决 -- 转
文章出处:http://blog.csdn.net/llqkk/article/details/2854558 由于是Linux新手,所以现在才开始接触线程编程,照着GUN/Linux编程指南中的一个 ...
- undefined reference to 'pthread_create'问题解决(转载)
转自:http://blog.csdn.net/llqkk/article/details/2854558 由于是Linux新手,所以现在才开始接触线程编程,照着GUN/Linux编程指南中的一个例子 ...
- 在linux下编译线程程序undefined reference to `pthread_create'
由于是Linux新手,所以现在才开始接触线程编程,照着GUN/Linux编程指南中的一个例子输入编译,结果出现如下错误:undefined reference to 'pthread_create'u ...
- Linux Ubuntu运行线程程序出现undefined reference to ‘pthread_create’和undefined reference to ‘pthread_join’错误。
Linux Ubuntu运行线程程序出现undefined reference to ‘pthread_create’和undefined reference to ‘pthread_join’错误. ...
随机推荐
- mybatis 详解(五)------动态SQL
前面几篇博客我们通过实例讲解了用mybatis对一张表进行的CRUD操作,但是我们发现写的 SQL 语句都比较简单,如果有比较复杂的业务,我们需要写复杂的 SQL 语句,往往需要拼接,而拼接 SQL ...
- IIS7.5应用程序池集成模式和经典模式的区别介绍
IIS7.5应用程序池集成模式和经典模式的区别介绍 作者: 字体:[增加 减小] 类型:转载 时间:2012-08-07 由于最近公司服务器上需要将iis的应用程序池全部都升级到4.0的框架,当 ...
- jQuery相关知识总结一
1day-jquery 1. 1 jQuery 1概念 * JavaScript(ECMA/DOM/BOM)在实际开发中,使用比较麻烦,有浏览器兼容问题. * JavaScript类库(JS库) 的目 ...
- js复习---string
对js的string的方法复习: 1.charCodeAt() 返回一个整数,代表指定位置字符串的unicode编码. strObj.charCodeAt(index) index 是处理字符的从零 ...
- Shell curl 和 wget 使用代理IP
Linux Shell 提供两个非常实用的命令来爬取网页,它们分别是 curl 和 wget curl 和 wget 使用代理 curl 支持 http.https.socks4.socks5 wge ...
- PhantomJS 与python的结合
待完善 一.简介 PhantomJS是一个基于webkit的JavaScript API.它使用QtWebKit作为它核心浏览器的功能,使用webkit来编译解释执行JavaScript代码.任何你可 ...
- shell 脚本编程之特殊变量
$0 当前脚本的文件名$n 传递给脚本或函数的参数.n 是一个数字,表示第几个参数.例如,第一个参数是$1,第二个参数是$2.$# 传递给脚本或函数的参数个数.$* 传递给脚本或函数的所有参数.$@ ...
- ThinkSNS+ 基于 Laravel master 分支,从 1 到 0,再到 0.1
什么是 ThinkSNS+ 09 年,由北京的团队开发了 ThinkSNS 涉足社交开源行业.这么多年累计不少客户.2014-2016,两年都在维护和开发之前基于 TP 的 ThinkSNS , 慢慢 ...
- 关于Tomcat无法启动的问题(Server Tomcat v7.0 Server at localhost failed to start.)
我们在使用tomcat时会发生Server Tomcat v7.0 Server at localhost failed to start.即tomcat无法启动的问题,如下图:
- Spring mvc登录拦截器
自己实现的第一个Spring mvc登录拦截器 题目要求:拒绝未登录用户进入系统,只要发现用户未登录,则将用户请求转发到/login.do要求用户登录 实现步骤: 1.在spring的配置文件中添加登 ...