undefined reference to 'pthread_create'的解决方法_Linux

照着GUN/Linux编程指南中的一个例子输入编译,结果出现如下错误:

undefined reference to 'pthread_create'
undefined reference to 'pthread_join'

问题原因:
    pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a,所以在使用pthread_create()创建线程,以及调用 pthread_atfork()函数建立fork处理程序时,需要链接该库。

问题解决:
    在编译中要加 -lpthread参数
    gcc thread.c -o thread -lpthread
    thread.c为你些的源文件,不要忘了加上头文件#include<pthread.h>

时间: 2024-09-12 02:53:12

undefined reference to 'pthread_create'的解决方法_Linux的相关文章

Linux下C编程:undefined reference to ‘pthread_create&#039;问题解决

undefined reference to 'pthread_create' undefined reference to 'pthread_join' 问题原因: pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a,所以在使用pthread_create()创建线程,以及调用 pthread_atfork()函数建立fork处理程序时,需要链接该库. 问题解决: 在编译中要加 -lpthread参数 gcc thread.c -o thread

Apache启动提示错误undefined symbol: libiconv_open解决方法_Linux

昨晚整合apache和php是实在找不到解决办法,Google 百度都转一圈了,总算在百度找回来解决方法,记录一下,这个问题是在apache启动时出现的: ./apachectl  start提示下面的错误: 复制代码 代码如下: httpd: Syntax error on line 57 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: /

Apache2.4.2编译安装2个常见错误和解决方法_Linux

尝试了一把从2005年以来第一次重大更新的新版本apache,不仅加入了云计算的基因更大幅提升了性能,I/O读写和内存占用优化程度比较大,主要是增加了一个enevt模式,测试效果不错. 实际我测试的 单纯的编译后静态文件和nginx的处理性能,确实已经相差不大,测试是使用ab测试的,单台nginx和阿帕奇测试后对比数据获得的结果,下次进行系统的测试在发测试数据,暂时只是测试了jpg图片 和html静态的文件 数据可能没代表性. 下面把编译的时候,常见的错误贴下: 错误一: 复制代码 代码如下:

php提示undefined index的几种解决方法_php技巧

平时用$_post[''],$_get['']获取表单中参数时会出现Notice: Undefined index: --------: 我们经常接收表单POST过来的数据时报Undefined index错误,如下: $act=$_POST['action']; 用以上代码总是提示 Notice: Undefined index: act in D:\test\post.php on line 20 另外,有时还会出现 Notice: Undefined variable: Submit ..

Yum安装中出现错误mirrorlist.txt的解决方法_Linux

发现问题 今天在使用Yum install命令安装软件的时候一直提示一个错误,错误提示如下面: # yum install mysql Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile YumRepo Error: All mirror URLs are not using ftp, http[s] or file. Eg. </HTML>/ removing mirrorlist with no

CentOS7中MariaDB修改datadir后无法启动的解决方法_Linux

发现问题 最近想把服务器的CentOS 6.8升级上CentOS7.但是失败了,重装了系统,重装以后挂载好数据盘后发现MariaDB起不来了,查journal log,只有一行warning can't create test file /var/lib/mysql/core.lower-test 解决方法 在网上查了一下,有两种方案      第一是说selinux导致的,但是ucloud的镜像默认就是关闭selinux的,所以不是这个问题      第二说是apparmor限制了进程的目录读

bash scp command not found的解决方法_linux shell

安装了centos6.0,由于选择了最小安装,很多包没有安装,因此一些常用的命令也不支持,如下:# scp -bash: scp: command not found 我的解决方法是:在一台运行正常的CentOS 5.6服务器上找到scp所在的包:##---以下命令在运行正常的CentOS 5.6上执行 复制代码 代码如下: # which scp /usr/bin/scp # rpm -qf /usr/bin/scp openssh-clients-4.3p2-72.el5 这么看来scp所在

linux bash中too many arguments问题的解决方法_linux shell

判断一个文件的内容是不是为空,使用语句: if test -z `cat filename` 当filename为空或者只有一行没有空格的字符串的时候,一切正常,反之,则会报:too many arguments,甚至是: binary operator expected之类的错误. 参考文章:http://www.ibm.com/developerworks/cn/linux/shell/bash/bash-2/index.html 原因分析:filename中的空格回车等迷惑了bash.如果

php编译安装常见错误大全和解决方法_linux shell

在CentOS编译PHP5的时候有时会遇到以下的一些错误信息,基本上都可以通过yum安装相应的库来解决.以下是具体的一些解决办法: 复制代码 代码如下: checking for BZip2 support- yes checking for BZip2 in default path- not found configure: error: Please reinstall the BZip2 distribution 解决方法:yum install bzip2-devel 复制代码 代码如