pthread_create, pthread_detach

Rainmaker의 이미지

cygwin 에서 작업을해서 컴파일하고 테스트를 마친 소스를

레드햇 8.0 머신에 옮겨서 컴파일하니

pthread_create, pthread_detach 가 undefiend reference 라고 나옵니다

혹시 레드햇 8.0 에선 이 함수들을 쓸 수 없는건가요?

아니면 같은 기능을 하는 다른 이름의 함수가 따로 존재하는건가요?

jyj9782의 이미지

제 생각엔 컴파일시에.. 라이브러리를 지정안해주셔서 발생한거 같습니다. 똑같은 함수들은 포직스 함수기에.. 제공하고 있어요..

gcc -o 파일 파일.c -lpthread

해주셔야죠 ^^

root@testbed:/home/c/glibc/pthread# cat > exam1.c
#include<stdio.h>
#include<pthread.h>

#define MAX 10

void *sub(void *tid){
        printf("S[%d]\n", tid);
        pthread_exit(tid);
}

main(){
pthread_t thread[MAX];
int ret, t;

        for(t=0;t<MAX;t++){
                printf("Create[%d]\n", t);
                pthread_create(&thread[t], NULL, sub, (void *)t);
        }

        pthread_exit(NULL);
}

root@testbed:/home/c/glibc/pthread# gcc -o exam1 exam1.c -lpthread
root@testbed:/home/c/glibc/pthread# ls -al exam1
-rwxr-xr-x    1 root     root        12565 2004-02-10 17:24 exam1
root@testbed:/home/c/glibc/pthread# ./exam1
Create[0]
S[0]
Create[1]
S[1]
Create[2]
S[2]
Create[3]
S[3]
Create[4]
S[4]
Create[5]
S[5]
Create[6]
S[6]
Create[7]
S[7]
Create[8]
S[8]
Create[9]
S[9]
root@testbed:/home/c/glibc/pthread# 

만약 안해주시면 라이브러리 참조못해서..
미참조 오류나요 아래처럼..

root@testbed:/home/c/glibc/pthread# 
root@testbed:/home/c/glibc/pthread# gcc -o exam1 exam1.c
/tmp/cc0sVwxh.o: In function `main':
/tmp/cc0sVwxh.o(.text+0x82): undefined reference to `pthread_create'
collect2: ld returned 1 exit status
root@testbed:/home/c/glibc/pthread# 

그럼.. ^^

힘내세요.

Rainmaker의 이미지

정말 감사합니다 ^^

깜빡했네요

다시한번 감사드립니다.

세상은 날 삼류라 하고 이 여자는 날 사랑이라 한다.