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’错误. ...
随机推荐
- java大数取余
java大数取余: 类方法:BigInteger.divideAndRemainder() 返回一个数组,key = 0为商key = 1为余数 import java.util.*; import ...
- 【我的漫漫跨考路】数据结构之单链表线性存储实现 Beta
正文之前 昨天晚上阶段性的完成了一部分数学的复习,所以今天打算撸一撸代码,然后发现提电脑忘指针.所以自己磕磕盼盼,对照了一下网上的代码,总算把线性存储单链表的数据类型实现,给自己写出来了. 废话不多说 ...
- ASP.NET Core 源码学习之 Logging[4]:FileProvider
前面几章介绍了 ASP.NET Core Logging 系统的配置和使用,而对于 Provider ,微软也提供了 Console, Debug, EventSource, TraceSource ...
- 安卓http源码查看器详解
1.效果图如下,输入网址就可以看到该网址的源码
- Java入门——(5)Java API
关键词:String类.StringBuffer类.System类.Math类.Random类.Date类.Calendar类.DateFormat类 API (Application Pro ...
- python——字符串 & 正则表达
raw字符串(原始字符串) 所见即所得,例如r''My's\n'' Python转义字符 在需要在字符中使用特殊字符时,python用反斜杠(\)转义字符.如下表: 转义字符 描述 \(在行尾时) 续 ...
- PhantomJS 与python的结合
待完善 一.简介 PhantomJS是一个基于webkit的JavaScript API.它使用QtWebKit作为它核心浏览器的功能,使用webkit来编译解释执行JavaScript代码.任何你可 ...
- javascript DOM 笔记
以下内容来自<javasript DOM 编程艺术>第二版 dom中三种重要的节点:元素节点.属性节点.文本节点. 几种节点的重要属性:nodeValue,nodeType(为数字1.2. ...
- Fedora25 将eclipse的快捷方式添加到Applications中
[root@localhost Downloads]# vi /usr/share/applications/eclipse.desktop 然后在里面添加如下内容: [Desktop Entry]N ...
- linux压缩解压命令
-c: 建立压缩档案 -x:解压 -t:查看内容 -r:向压缩归档文件末尾追加文件 -u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一 ...