怎样彻底解决"undefined reference to `pthread_create'"问题

本文解答了在使用gcc编译含有pthread的程序时遇到的undefined reference to 'pthread_create'原因是未链接pthread相关库。通过在编译中加入-lpthread参数并确保包含头文件,可以解决此问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在编写pthread有关的程序时,编译时老是报"undefined reference to `pthread_create'"的错误,
原因是没有链接pthread相关的库,gcc加上-lrt就可以了.
我想怎样默认去链接这个库了?不要再加个"-lrt"了
也就是"/usr/lib/"下的libpthread.a,

应该在哪个配置文件中进行配置了?


问题解决:
    在编译中要加 -lpthread参数
    gcc thread.c -o thread -lpthread
    thread.c为你些的源文件,不要忘了加上头文件#include<pthread.h>
undefined reference to 'pthread_create'问题解决 - llqkk的专栏 - 优快云博客 (28 September 2009)
http://blog.youkuaiyun.com/llqkk/archive/2008/08/31/2854558.aspx

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值