分页: 1 / 1

[问题]新手多线程编程问题

发表于 : 2007-09-24 22:26
leran0222
程序代马如下:

#include<stdio.h>
#include<pthread.h>

void thread (void)
{
int i;
for(i=0;i<3;i++)
{
printf("This is a pthread\n");
}
}

int main(void)
{
pthread_t id;
int i,ret;
ret=pthread_create(&id,NULL,(void *)thread,NULL);
if(ret!=0)
{
printf("Create Thread Error!\n");
// exit(0);
}
for(i=0;i<3;i++)
{
printf("This Is The Main Process!!!\n");
}
pthread_join(id,NULL);
return (0);
}


编译后的错误信息如下:

leran0222@leran0222-desktop:~/C$ gcc -o mul mul.c
/tmp/cc4uiXHG.o: In function `main':
mul.c:(.text+0x58): undefined reference to `pthread_create'
mul.c:(.text+0x9f): undefined reference to `pthread_join'
collect2: ld returned 1 exit status
leran0222@leran0222-desktop:~/C$

怎么解决这个问题???
是因为我的电脑里面去我少头文件么 ???

发表于 : 2007-09-24 22:31
leran0222
可是在/usr/include/bits目录下有pthreadtypes.h头文件阿 !!!

发表于 : 2007-09-24 22:59
wkt
加上 -lpthread看看

发表于 : 2007-09-24 23:08
windwiny
这是链接出错

加上 -lpthread 参数

发表于 : 2007-09-26 13:17
leran0222
谢谢 几位 了
问题解决
加上 -lpthread就好了