当前位置: 技术问答>linux和unix
linux下开发多线程程序,老是报这个错,怎么了?
来源: 互联网 发布时间:2015-11-16
本文导语: [root@localhost /]# gcc pthread.c /tmp/cck3yHMe.o(.text+0x2af): In function `main': : undefined reference to `pthread_create' /tmp/cck3yHMe.o(.text+0x2c4): In function `main': : undefined reference to `pthread_create' /tmp/cck3yHMe.o(.text+0x2d6): In function `main...
[root@localhost /]# gcc pthread.c
/tmp/cck3yHMe.o(.text+0x2af): In function `main':
: undefined reference to `pthread_create'
/tmp/cck3yHMe.o(.text+0x2c4): In function `main':
: undefined reference to `pthread_create'
/tmp/cck3yHMe.o(.text+0x2d6): In function `main':
: undefined reference to `pthread_join'
/tmp/cck3yHMe.o(.text+0x2e8): In function `main':
: undefined reference to `pthread_join'
collect2: ld returned 1 exit status
我的pthread.c文件中#include 了 pthread.h头文件啊,
而且我查看了这个头文件,里面定久了pthread_create和pthread_join这两个函数呀.为什么还报错.
/tmp/cck3yHMe.o(.text+0x2af): In function `main':
: undefined reference to `pthread_create'
/tmp/cck3yHMe.o(.text+0x2c4): In function `main':
: undefined reference to `pthread_create'
/tmp/cck3yHMe.o(.text+0x2d6): In function `main':
: undefined reference to `pthread_join'
/tmp/cck3yHMe.o(.text+0x2e8): In function `main':
: undefined reference to `pthread_join'
collect2: ld returned 1 exit status
我的pthread.c文件中#include 了 pthread.h头文件啊,
而且我查看了这个头文件,里面定久了pthread_create和pthread_join这两个函数呀.为什么还报错.
|
gcc pthread.c -lpthread试试看
|
没有使用线程库,解决方法如楼上所说