首页 > 编程语言 > 详细

c++使用thread类时编译出错,对‘pthread_create’未定义的引用

时间:2018-02-09 17:14:35      阅读:368      评论:0      收藏:0      [点我收藏+]
/tmp/ccM2tvqF.o: In function `main':
thread_c.c:(.text+0x1f): undefined reference to `pthread_create'
thread_c.c:(.text+0x52): undefined reference to `pthread_create'
thread_c.c:(.text+0x7d): undefined reference to `pthread_join'
thread_c.c:(.text+0xa9): undefined reference to `pthread_join'
collect2: ld returned 1 exit status


查了老半天,以为代码的问题,最后才知道是因为pthread库不是Linux系统默认的库,连接时需要使用库libpthread.a,所以在使用pthread_create创建线程时,在编译中要加-lpthread参数:gcc test_thread.c -lpthread -o test_thread. 加上这个以后编译成功!

c++使用thread类时编译出错,对‘pthread_create’未定义的引用

原文:http://blog.51cto.com/9409270/2070694

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!