我寫了一個程式 欲印出下列訊息:
This is Hello thread.
Thread ID:
Argument:100
------------------------------------------------
程式碼如下
------------------------------------------------
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
void *PrintHello(void *arg)
{
printf("This is Hello thread.\n");
printf("Thread ID: %lu\n",pthread_self());
printf("Argument: %d\n",(int) arg);
pthread_exit(NULL);
}
int main()
{
pthread_t thread;
int rc,t = 100;
rc = pthread_create(&thread,NULL,PrintHello,(void *)t);
if(rc){
printf("ERROR; return the code from the pthread_creat() is %d\n",rc);
exit(-1);
}
rc = pthread_join(thread,NULL);
if(rc){
printf("ERROR; return the code from the pthread_join() is %d\n",rc);
exit(-1);
}
return 0;
}
------------------------(分隔線)----------------------------
結果gcc編譯時出現以下訊息:
/tmp/cco6vngs.o: In function `main':
thread_example.c:(.text+0x79): undefined reference to `pthread_create'
thread_example.c:(.text+0xb9): undefined reference to `pthread_join'
collect2: ld returned 1 exit status
這是哪裡出問題 小弟不太懂 有那位大大能回答我的 感激不盡
--
This is Hello thread.
Thread ID:
Argument:100
------------------------------------------------
程式碼如下
------------------------------------------------
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
void *PrintHello(void *arg)
{
printf("This is Hello thread.\n");
printf("Thread ID: %lu\n",pthread_self());
printf("Argument: %d\n",(int) arg);
pthread_exit(NULL);
}
int main()
{
pthread_t thread;
int rc,t = 100;
rc = pthread_create(&thread,NULL,PrintHello,(void *)t);
if(rc){
printf("ERROR; return the code from the pthread_creat() is %d\n",rc);
exit(-1);
}
rc = pthread_join(thread,NULL);
if(rc){
printf("ERROR; return the code from the pthread_join() is %d\n",rc);
exit(-1);
}
return 0;
}
------------------------(分隔線)----------------------------
結果gcc編譯時出現以下訊息:
/tmp/cco6vngs.o: In function `main':
thread_example.c:(.text+0x79): undefined reference to `pthread_create'
thread_example.c:(.text+0xb9): undefined reference to `pthread_join'
collect2: ld returned 1 exit status
這是哪裡出問題 小弟不太懂 有那位大大能回答我的 感激不盡
--
All Comments