|
正在学习线程程序编写,老是编译错误,帮我看看,谢谢!
程序:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
void * mythread(void * arg);
int main()
{
pthread_t th;
int kk;
kk=pthread_create(&th,NULL,mythread,NULL);
if (kk!=0)
exit(0);
for(;;)
{
printf("Main process\n");
sleep(3);
}
}
void * mythread(void * arg)
{
for(;;)
{
printf("Thread\n");
sleep(1);
}
return NULL;
}
错误信息:
[youngtrips@localhost ~]$ g++ -o pthreadtest test.cpp
/tmp/cclQnx0K.o: In function `main':
test.cpp.text+0x3e): undefined reference to `pthread_create'
collect2: ld 返回 1
[youngtrips@localhost ~]$ |
|