난 다음 데모 끕니까 웹 (https://computing.llnl.gov/tutorials/pthreads/) 에서 인계받아
#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);
}
그러나 내가 내 시스템 (Ubuntu Linux 실행 9.04) I get it on 컴파일하십시오 다음 오류:
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 to `pthread_create'
collect2: ld returned 1 exit status
, Incorrect.&l br> 지금까지 이 문제의 답을 모두 있다. 올바른 linux용 명령은 다음과 같습니다.
gcc -pthread -o term term.c
일반적으로 라이브러리를 소스 및 명령줄의 객체에는 따라야 할 수 없는 '및' 레프 트레더 ";; s # 39 option" it& 라리브러리 사양명세. 시스템에 설치된 리브프트리아드리아 '불과'
gcc -lpthread ...
링크 못합니다.
몇 가지 예를 들어, 이를 통해 아쿠탈리 컴파일하십시오 데사용됩니다 pthreads 코드는 명령 아래 표에 나와 계속할 경우 판독값 다음 자습서는: