Linux中未定義的對p線程_CREATE的引用我從網上獲得了下面的演示https:/Computing.llnl.gov/tutorials/p線程/#include <pthread.h>#include <stdio.h>#define NUM_THREADS 5void *PrintHello(void *threadid){
long tid;
tid = (long)threadid;
printf("Hello World! It's me, thread #%ld!\n", tid);
pthread_exit(NULL);}int main (int argc, char *argv[]){
pthread_t threads[NUM_THREADS];
int rc;
long t;
for(t=0; t<NUM_THREADS; t++){
printf("In main: creating thread %ld\n", t);
rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
if (rc){
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}
pthread_exit(NULL);}但是,當我在我的機器上編譯它(運行UbuntuLinux 9.04)時,我得到以下錯誤:corey@ubuntu:~/demo$ gcc -o term term.c
term.c: In function ‘main’:term.c:23: warning: incompatible implicit declaration of built-in function ‘exit’/tmp/cc8BMzwx.o:
In function `main':term.c:(.text+0x82): undefined reference to `pthread_create'collect2: ld returned 1 exit status這對我來說沒有任何意義,因為標題包括pthread.h,它應該有pthread_create功能。有什么問題嗎?
- 3 回答
- 0 關注
- 766 瀏覽
添加回答
舉報
0/150
提交
取消