问题原因

pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a.

所以在使用pthread_create()创建线程时,需要链接该库。

1. gcc 解决方案
在编译中要加 -pthread参数

 gcc thread.c -o thread -pthread

2. cmake 解决方案

修改CMakeLists.txt  TARGET_LINK_LIBRARIES中加入 pthread

ADD_EXECUTABLE(your_executable ${source_files})TARGET_LINK_LIBRARIES( your_executable
pthread
)

linux cmake 多线程 错误 undefined reference to 'pthread_create'相关推荐

  1. linux 线程操作问题undefined reference to ‘pthread_create‘的解决办法(cmake)

    linux 线程操作问题undefined reference to 'pthread_create'的解决办法(cmake) 参考文章: (1)linux 线程操作问题undefined refer ...

  2. linux 内核编译错误 undefined reference to '__mutex_lock_slowpath'

    解决办法: 更改 kernel/mutex.c 中的声明以强制将函数保留在目标文件中.您可以像这样使用gcc属性扩展名 __used,具体方法如下: vi kernel/mutex.c 将60行内容, ...

  3. C/C++ linux 多线程编程报错 :undefined reference to `pthread_create‘

    文档声明: 以下资料均属于本人在学习过程中产出的学习笔记,如果错误或者遗漏之处,请多多指正.并且该文档在后期会随着学习的深入不断补充完善.感谢各位的参考查看. 笔记资料仅供学习交流使用,转载请标明出处 ...

  4. undefined reference to `pthread_create‘(linux下Clion使用thread报错)

    完整报错: ====================[ Build | AsyncLogger | Debug ]============================= /snap/clion/1 ...

  5. Linux下undefined reference to ‘pthread_create’问题解决

    Linux下undefined reference to 'pthread_create'问题解决 在试用Linux 线程模块时,试用pthread_create 函数. 编译命令为 gcc main ...

  6. Linux下undefined reference to ‘pthread_create’问题解决 zz

    Linux下undefined reference to 'pthread_create'问题解决 zz 参考文章: (1)Linux下undefined reference to 'pthread_ ...

  7. [ c++] cmake 编译时 undefined reference to `std::cout‘ 错误的解决方案

    [ c++] cmake 编译时 undefined reference to `std::cout' 错误的解决方案 参考文章: (1)[ c++] cmake 编译时 undefined refe ...

  8. linux使用gcc编译报错“undefined reference to `pthread_create'”

    下面这个例子通过一个代码说明两个线程关联一个函数,实现并发操作,预期结果这两个线程都使用了print函数,它们各自执行各自的,不会因为使用了同一个函数而受到影响. my_test.cpp #inclu ...

  9. undefined reference to 'pthread_create'问题解决

    由于是Linux新手,所以现在才开始接触线程编程,照着GUN/Linux编程指南中的一个例子输入编译,结果出现如下错误: undefined reference to 'pthread_create' ...

最新文章

  1. 网管应当如何管理Windows操作系统
  2. vuejs和webpack项目(VueComponent)初尝试——瀑布流组件
  3. Spring写第一个程序HelloSpring
  4. 大规模图嵌入 示例_ICLR 2020 | 基于谱方法的高效多级图嵌入框架
  5. 学python将来做什么工作_学Python编程能做什么工作?从事什么岗位?——这些问题你知道吗?...
  6. 类型转换操作符(C++)
  7. android 改机型玩王者,全机型60帧一键修改
  8. gensim实现TF-IDF和LDA模型、sklearn实现聚类
  9. App集成ApplePay
  10. ML机器学习基础的编程技巧:
  11. Rocketmq 消息的同步发送,异步发送,oneway方式
  12. 扒皮下音悦台的“返回顶部”图标效果
  13. 微信相关账号需要哪些资质
  14. 【数论】因数与倍数(一)质数与合数
  15. Python 将网易云歌单迁移到QQ音乐
  16. 职高学生计算机学情分析,高职学生学情分析
  17. (英文版)吴恩达机器学习第三周笔记
  18. 数码印花为何打印精度太高,成品却越不清晰?
  19. XCP实战系列介绍06-CANape标定及标定后hex生成操作指导
  20. 智能对话架构师速成秘诀在这里

热门文章

  1. 5G NGC — CAPIF 网络能力开放框架
  2. 互联网协议 — L2TP 二层隧道协议
  3. C 家族程序设计语言发展史
  4. HTTP深入浅出 http请求
  5. Linux 6.8 root密码丢失找回
  6. 深入Java虚拟机——类型装载、连接(转)
  7. 6-java代码片段
  8. GlusterFS配置管理(五)
  9. R语言文本挖掘NASA数据网络分析,tf-idf和主题建模
  10. 因热爱而编码,创造至美生活,挑战高效工作 阿里云智能开发者创新应用大赛全记录...