当前位置: 技术问答>linux和unix
linux多线程编成
来源: 互联网 发布时间:2016-08-24
本文导语: #include #include #include void *first() { printf("first pthread-----ABCn"); } void *second() { printf("second pthread-----ABCn"); } int main() { printf("mian pthread----ABCn"); pthread_t fthread; pthread_t sthread; pthread_create(&fthread,NULL,first,NULL); pthread_create(...
#include
#include
#include
void *first()
{
printf("first pthread-----ABCn");
}
void *second()
{
printf("second pthread-----ABCn");
}
int main()
{
printf("mian pthread----ABCn");
pthread_t fthread;
pthread_t sthread;
pthread_create(&fthread,NULL,first,NULL);
pthread_create(&sthread,NULL,second,NULL);
pthread_join(fthread,NULL);
pthread_join(sthread,NULL);
return 0;
}
我编译提示错误如下
fily@zhaoyf:/media/work/develop/iscsitarget/usr$ gcc -o thread thread.c
/tmp/ccRbUIwW.o: In function `main':
thread.c:(.text+0x4e): undefined reference to `pthread_create'
thread.c:(.text+0x66): undefined reference to `pthread_create'
thread.c:(.text+0x74): undefined reference to `pthread_join'
thread.c:(.text+0x82): undefined reference to `pthread_join'
collect2: ld returned 1 exit status
高手帮忙,我错在哪里了?
我使用的是debian5linux
#include
#include
void *first()
{
printf("first pthread-----ABCn");
}
void *second()
{
printf("second pthread-----ABCn");
}
int main()
{
printf("mian pthread----ABCn");
pthread_t fthread;
pthread_t sthread;
pthread_create(&fthread,NULL,first,NULL);
pthread_create(&sthread,NULL,second,NULL);
pthread_join(fthread,NULL);
pthread_join(sthread,NULL);
return 0;
}
我编译提示错误如下
fily@zhaoyf:/media/work/develop/iscsitarget/usr$ gcc -o thread thread.c
/tmp/ccRbUIwW.o: In function `main':
thread.c:(.text+0x4e): undefined reference to `pthread_create'
thread.c:(.text+0x66): undefined reference to `pthread_create'
thread.c:(.text+0x74): undefined reference to `pthread_join'
thread.c:(.text+0x82): undefined reference to `pthread_join'
collect2: ld returned 1 exit status
高手帮忙,我错在哪里了?
我使用的是debian5linux
|
编译的时候 忘记添加 -l pthread
需要把线程的库加进去
需要把线程的库加进去