리눅스 pthread_create에서 undefined reference이 나옵니다. 도와주실분 안계시나요

조회수 22001회

발생하는 문제 및 실행환경

https://computing.llnl.gov/tutorials/pthreads/ 를 따라하고 있는데 밑의 코드를 실행하면 자꾸 에러가 뜹니다.

pthread.h를 include했는데도 자꾸 pthread_create가 정의되지 않았다고 뜨는데 왜 이런건가요? 제 컴퓨터는 Ubuntu Linux 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 topthread_create' collect2: ld returned 1 exit status

소스코드

#include <pthread.h>
#include <stdio.h>
#define NUM_THREADS     5

void *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);
}

2 답변

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)