[問題] 關於undefined reference to pthread...囧
遇到的問題: (題意請描述清楚)
我在寫pthread的練習程式
明明就有include pthread.h
compile時卻一直出現
"undefined reference to pthread_create"跟
"undefined reference to pthread_join"的訊息
麻煩有經驗的前輩指點一下該如何解決
感恩 QQ"
開發平台: (例: VC++ or gcc/g++ or Dev-C++, Windows or Linux)
Linux
有問題的code: (請善用置底文標色功能)
#include <pthread.h>
#include <stdio.h>
void *ChildThread1(void *arg);
void *ChildThread2(void *arg);
int main()
{
pthread_t thread1, thread2;
void *return_t1, *return_t2;
int ret1, ret2;
ret1=pthread_create(&thread1,NULL,ChildThread1,NULL);
ret2=pthread_create(&thread2,NULL,ChildThread2,NULL);
if(ret1!=0)
{
fprintf(stderr,"fail to creat a thread");
exit(-1);
}
if(ret2!=0)
{
fprintf(stderr,"fail to creat a thread");
exit(-1);
}
pthread_join(thread1,&return_t1);
pthread_join(thread2,&return_t2);
printf("Thread 1 returns %d\n", return_t1);
printf("Thread 2 returns %d\n", return_t2);
return 0;
}
void *ChildThread1(void *arg)
{
printf("I am Thread 1\n");
pthread_exit(0);
}
void *ChildThread2(void *arg)
{
printf("I am Thread 2\n");
pthread_exit(0);
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.134.134.242
→
03/17 11:24, , 1F
03/17 11:24, 1F
→
03/17 11:45, , 2F
03/17 11:45, 2F