POSIX Thread 를 사용하려고 합니다.
      글쓴이: litnsio2 / 작성시간: 금, 2004/04/02 - 6:29오후    
  
  다음과 같은 예제 프로그램을 작성하였습니다.
간단하게 헬로월드를 출력하는 프로그램입니다..
#include <pthread.h>
#include <stdio.h>
#define NUM_THREADS 5
void *printHello(void *threadid)
{
	printf("\n%d: Hello, World!\n", threadid);
	pthread_exit(NULL);
}
int main(int argc, char *argv[])
{
	pthread_t threads[NUM_THREADS];
	int rc, t;
	for(t=0; t<NUM_THREADS; ++t)
	{
		printf("Creating thread %d\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);
	
	return 0;
}
그런데 컴파일시에 문제가 있더군요.
Quote:
[dduk@ns posix]$ gcc hello.c
/tmp/cca75Qoy.o(.text+0x6d): In function `main':
: undefined reference to `pthread_create'
collect2: ld returned 1 exit status
[dduk@ns posix]$
제 생각에는 pthread.h 와 함께 사용되는 라이브러리도
gcc 커맨드 라인에 지정해주어야 할 것 같은데... (아닌가용?)
어떻게 해 줘야 할지 모르겠습니다...;;
Forums: 


pthread라이브러리를 링킹 해주어야 합니다.gcc옵션에
pthread라이브러리를
링킹 해주어야 합니다.
gcc옵션에 -lpthread해주세요.
와..
감사합니다 ^^
잘 되네요 ^^
댓글 달기