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

linux下编译多线程程序, undefined reference to `pthread_create',undefined reference to `pthread_join'

2017-10-23 13:41 756 查看
问题描述:hero@ubuntu:~/WORK/for_xc7z035/app/sdr_7010$ gcc -o ./test ./test.c

/tmp/cc7BcXdf.o: In function `main':

test.c:(.text+0x1d7): undefined reference to `pthread_create'

test.c:(.text+0x1fb): undefined reference to `pthread_create'

test.c:(.text+0x21f): undefined reference to `pthread_create'

test.c:(.text+0x233): undefined reference to `pthread_join'

test.c:(.text+0x247): undefined reference to `pthread_join'

test.c:(.text+0x267): undefined reference to `pthread_join'

collect2: error: ld returned 1 exit status

问题原因:

  1, pthread 库不是 Linux 系统默认的库,在编译多线程程序时,需要在编译命令中添加链接libpthread.a库。

 2,忘了加上头文件#include<pthread.h>

问题解决:

    在编译中要加 -lpthread参数

    gcc  ./test.c -o ./test -lpthread

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐