当前位置: 技术问答>linux和unix
为什么pthread_create`编译通不过
来源: 互联网 发布时间:2015-08-03
本文导语: #include #include #include void donothing() { } int main(int argc, char *argv[]) { pthread_t thread; pthread_create(&thread,NULL,(void*)donothing,NULL); } 下面是编译命令: [groupmerit@localhost mutithread]$ gcc -c main.c [groupmerit@localhost mutithrea...
#include
#include
#include
void donothing()
{
}
int main(int argc, char *argv[])
{
pthread_t thread;
pthread_create(&thread,NULL,(void*)donothing,NULL);
}
下面是编译命令:
[groupmerit@localhost mutithread]$ gcc -c main.c
[groupmerit@localhost mutithread]$ gcc -o main main.o
main.o(.text+0x33): In function `main':
: undefined reference to `pthread_create'
collect2: ld returned 1 exit status
为什么生成可执行文件会报pthread_create没定义
#include
#include
void donothing()
{
}
int main(int argc, char *argv[])
{
pthread_t thread;
pthread_create(&thread,NULL,(void*)donothing,NULL);
}
下面是编译命令:
[groupmerit@localhost mutithread]$ gcc -c main.c
[groupmerit@localhost mutithread]$ gcc -o main main.o
main.o(.text+0x33): In function `main':
: undefined reference to `pthread_create'
collect2: ld returned 1 exit status
为什么生成可执行文件会报pthread_create没定义
|
gcc -o main main.o -lpthread
要连接库。
要连接库。