gcc 컴파일할때 -I./include 하면 include 헤더파일만 참조되나요?

brian.ryu의 이미지

gcc 컴파일시에 -I 옵션을 이용하며 지정된 헤더파일만 사용하나요?(자동으로 -nostdinc 가 되는 건가요?)

wariua의 이미지

man gcc 결과 중 일부입니다.

Quote:
-Idir
Add the directory dir to the head of the list of directories to be
searched for header files. This can be used to override a system
header file, substituting your own version, since these directories
are searched before the system header file directories. However,
you should not use this option to add directories that contain ven-
dor-supplied system header files (use -isystem for that). If you
use more than one -I option, the directories are scanned in left-
to-right order; the standard system directories come after.

"replace"가 아닌 "add"입니다. 사실 이런 건 manpage에서 정보를 찾는 것보다 샘플을 만들어서 테스트를 해보는 게 더 빠를 수도 있지요 8)

$PWD `date`

monpetit의 이미지

기본 헤더 디렉토리보다 먼저 검색합니다.

brian.ryu의 이미지

이걸 해결이라고 해야 하나요?

/aaa/aaa.c
/bbb/bbb.h

1번시도
aaa.c 에서
#include "bbb/bbb.h" 를 첨부하고

aaa.c 컴파일시에 -I./bbb 를 했으나 에러가 쭈루룩.....

2번시도
#include <bbb/bbb.h> 를 첨부하고

aaa.c 컴파일시에 -I./bbb 를 했으나 에러가 쭈루룩......

혹시나해서 /aaa/include/bbb/bbb.c 로 디렉토리 구조를 수정했습니다.
그리곤, 2번 시도를 해보니 와~ 성공......

-I옵션을 사용하려면 include 디렉토리를 만들고 그 안에 들어 있는 헤더파일을 찾는가 봅니다.

제가 성공한 형태가 -I 옵션을 사용하기 위한 올바른 방법인가요?