您的位置:首页 > 运维架构 > Linux

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

2016-02-18 15:23 537 查看
问题的原因:pthread不是Linux下的默认的库,也就是在链接的时候,无法找到phread库中的函数的入口地址,于是链接会失败。

解决:在gcc编译的时候,附加要加 -lpthread参数即可解决。

root@ubuntu:/test/linux/20160218# gcc threadid.c
/tmp/cc2buUlJ.o: In function `main':
threadid.c:(.text+0x2e6): undefined reference to `pthread_create'
collect2: ld returned 1 exit status
root@ubuntu:/test/linux/20160218# gcc -lpthread threadid.c
root@ubuntu:/test/linux/20160218# ./a.out
main thread: pid 5720 tid 3077879488 (0xb774b6c0)
new thread:  pid 5720 tid 3077876592 (0xb774ab70)
root@ubuntu:/test/linux/20160218#
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: