栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【Ubuntu】【C++】报错:undefined reference to `pthread

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【Ubuntu】【C++】报错:undefined reference to `pthread

背景:g++ test.cpp -o test 

报错:undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status

分析:pthread不是linux下的默认的库。在链接的时候,无法找到pthread库中函数的入口地址,所以链接会失败。提示:clang: error: linker command failed with exit code 1

解决:gcc编译时,加 ***-lpthread***参数,声明需要连接线程库,才能调用pthread.h中声明的函数。

​            g++ test.cpp -o test -lpthread

成功编译。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/997255.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号