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

来源:互联网 发布:阿里云 电话归属地 编辑:程序博客网 时间:2024/06/04 20:05

问题的原因: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 statusroot@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# 



0 0