關於pthread.h - Linux
By Gilbert
at 2009-11-22T15:37
at 2009-11-22T15:37
Table of Contents
我寫了一個程式 欲印出下列訊息:
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
這是哪裡出問題 小弟不太懂 有那位大大能回答我的 感激不盡
--
Tags:
Linux
All Comments
By Genevieve
at 2009-11-22T21:25
at 2009-11-22T21:25
By Ula
at 2009-11-23T06:16
at 2009-11-23T06:16
By Anonymous
at 2009-11-27T12:01
at 2009-11-27T12:01
Related Posts
超級新手的苦惱
By Todd Johnson
at 2009-11-22T00:43
at 2009-11-22T00:43
ifconfig的訊息 想請教一下
By Hamiltion
at 2009-11-21T23:59
at 2009-11-21T23:59
ifconfig的訊息 想請教一下
By Frederica
at 2009-11-21T23:30
at 2009-11-21T23:30
CentOS 4.8 用 yum 升到 5.x ?
By Joe
at 2009-11-21T23:26
at 2009-11-21T23:26
ifconfig的訊息 想請教一下
By Liam
at 2009-11-21T22:06
at 2009-11-21T22:06