728x90
*Ubuntu 20.04 에서 컴파일했습니당..
빌드시 아래 메시지가 뜬다면....
pthread library 가 제대로 링크 되지 않은것이다...
undefined reference to 'pthread_cancel'
undefined reference to `pthread_create'
undefined reference to `pthread_join'
이거 배워놓고 자꾸 잊어먹는다...
pthread.h 를 포함하고 pthread 관련 함수 사용시
compile 시 -lpthread 옵션을 꼭 넣어주어야한다!
make file 작성시에는
CC = gcc
CFLAGS =
LDFLAGS = -lpthread
[target] : [prerequisites(.o file 등)]
$(CC) -o $@ $< $(LDFLAGS)
요렇게 작성하면 되고
직접 컴파일할때는
gcc -o [target] [소스코드] -lpthread
이렇게 옵션 넣어주면 된다...
그러나 lpthread 말고 pthread 옵션을 넣어도 되는데
둘의 차이는
lpthread 는 pthread 라이브러리와 링크만 해주고
pthread 는 라이브러리 링크+매크로 사용이 가능하다.
그래서 pthread 사용을 추천하는 글이 많다...
그러나 pthread 옵션은 운영체제에 따라 동작하지 않을 수 있다... 아마 그래서 내 실습자료도 lpthread 옵션을 사용한듯허당!
출처 :
728x90
'프로그래밍 공부 > OS' 카테고리의 다른 글
[Linux] IPC(Inter Process Communication) 간단한 개념 (0) | 2021.11.22 |
---|---|
[Linux] close(0), close(1) (0) | 2021.11.17 |
[Linux] signal systemcall 로 Synchronus 프로그래밍 하기 (0) | 2021.11.11 |
[Linux] 표준 입력, 표준 출력, 표준 에러 출력, 파일디스크립터 (0) | 2021.10.30 |
[Linux] scp 오류 : No such File or Directory 해결 (0) | 2021.09.26 |