码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-02-09 17:35:35      阅读:362      评论:0      收藏:0      [点我收藏+]

标签:系统默认   join   col   linu   参数   create   线程   创建线程   cti   

/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’未定义的引用

标签:系统默认   join   col   linu   参数   create   线程   创建线程   cti   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!