어떤 unistd.h 파일이로드되는지 어떻게 알 수 있습니까? 다음 지시문이

unistd.hUbuntu Linux에 여러 파일이 있습니다. 에 하나 있습니다 /usr/include/asm/unistd.h. 이 파일에는 다음 지시문이 있습니다.

# ifdef __i386__
#  include "unistd_32.h"
# else
#  include "unistd_64.h"
# endif

해당 폴더에서 해당 파일 ( unistd_32.hunistd_64.h)을 찾을 수 있습니다 .

그러나이 지시문으로 시작하는 /usr/src/linux-headers-2.6.31-22/include/asm-generic/또 다른 unistd.h것이 있습니다.

#if !defined(_ASM_GENERIC_UNISTD_H) || defined(__SYSCALL)
#define _ASM_GENERIC_UNISTD_H

그래서 질문은 : 어느 것이로드되었는지 어떻게 알 수 있습니까? Java로 런타임에서 확인할 수있는 방법이 있습니까?



답변

gcc포함 파일을 찾기위한 컴파일러 다음의 정확한 규칙 은 http://gcc.gnu.org/onlinedocs/cpp/Search-Path.html에 설명되어 있습니다.

포함 파일의 출처를 찾는 빠른 명령 줄 트릭은 다음과 같습니다. 1

echo '#include <unistd.h>' | gcc -E -x c - > unistd.preprocessed

그런 다음 unistd.preprocessed파일 을 보면 다음 과 같은 줄이 나타납니다.

# 1 "/usr/include/unistd.h" <some numbers>

이것들은 다음 # number ...줄 까지 (다음 줄 까지 ) file에서 온다는 것을 알려줍니다 /usr/include/unistd.h.

따라서 포함 된 전체 파일 목록을 알고 싶다면 # number줄을 grep 할 수 있습니다 .

echo '#include <unistd.h>' | gcc -E -x c - | egrep '# [0-9]+ ' | awk '{print $3;}' | sort -u*emphasized text*

내 우분투 10.04 / gcc 4.4.3 시스템에서 다음을 생성합니다.

$ echo '#include <unistd.h>' | gcc -E -x c - | egrep '# [0-9]+ ' | awk '{print $3;}' | sort -u
"<built-in>"
"<command-line>"
"<stdin>"
"/usr/include/bits/confname.h"
"/usr/include/bits/posix_opt.h"
"/usr/include/bits/predefs.h"
"/usr/include/bits/types.h"
"/usr/include/bits/typesizes.h"
"/usr/include/bits/wordsize.h"
"/usr/include/features.h"
"/usr/include/getopt.h"
"/usr/include/gnu/stubs-64.h"
"/usr/include/gnu/stubs.h"
"/usr/include/sys/cdefs.h"
"/usr/include/unistd.h"
"/usr/lib/gcc/x86_64-linux-gnu/4.4.3/include/stddef.h"

1 참고 : 포함 파일의 검색 경로는 -I명령 줄 옵션으로 수정됩니다 . 따라서 호출에 -I path
인수를 추가해야합니다 gcc. 당신은 C ++ 소스를 컴파일하는 경우 또한, 당신은 대체해야 -x c와 함께 -x c++.


답변