我有这个代码:
#include <stdio.h>
#include <pthread.h>
void* cuoco(void* arg)
{
fprintf(stderr,"Inizio codice cuoco\n");
fprintf(stderr,"Fine codice cuoco\n");
return NULL;
}
void* cameriere(void* arg)
{
fprintf(stderr,"Inizio codice cameriere\n");
fprintf(stderr,"Fine codice cameriere\n");
return NULL;
}
void* cliente(void* arg)
{
fprintf(stderr,"Inizio codice cliente\n");
fprintf(stderr,"Fine codice cliente\n");
return NULL;
}
int main(int argc, char* argv[])
{
void* (*routine)(void*);
routine=cuoco;
pthread_t thread_cuoco,thread_cameriere,thread_cliente;
pthread_create(&thread_cuoco,NULL,routine,NULL);
return 0;
}
在编译器选项中我插入-lp线程
但它说:
“对 pthread_create 的未定义引用”
我使用ubuntu 10.10,所以我已经安装了pthread库,我无法弄清楚这个错误的原因。
使用 -lpthread 作为最后一个编译器标志。
例子:gcc -o sample sample.c -lpthread
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)