当我用Linux编写C程序,然后使用gcc编译它们时,我总是对那些头文件在哪里感到好奇。例如,在哪里stdio.h。更一般地说,在哪里stdbool.h?
stdio.h
stdbool.h
我想知道的不仅是它在哪里,还有如何获得这些地方,例如,使用shell命令或使用C编程语言。
gcc -H ...将打印每个包含文件的完整路径,作为常规编译的副作用。-fsyntax- only另外使用使其不创建任何输出(它仍然会告诉您程序是否有错误)。示例(Linux,gcc-4.7):
gcc -H ...
-fsyntax- only
$ cat > test.c #include <stdbool.h> #include <stdio.h> ^D $ gcc -H -fsyntax-only test.c . /usr/lib/gcc/x86_64-linux-gnu/4.7/include/stdbool.h . /usr/include/stdio.h .. /usr/include/features.h ... /usr/include/x86_64-linux-gnu/bits/predefs.h ... /usr/include/x86_64-linux-gnu/sys/cdefs.h .... /usr/include/x86_64-linux-gnu/bits/wordsize.h ... /usr/include/x86_64-linux-gnu/gnu/stubs.h .... /usr/include/x86_64-linux-gnu/bits/wordsize.h .... /usr/include/x86_64-linux-gnu/gnu/stubs-64.h .. /usr/lib/gcc/x86_64-linux-gnu/4.7/include/stddef.h .. /usr/include/x86_64-linux-gnu/bits/types.h ... /usr/include/x86_64-linux-gnu/bits/wordsize.h ... /usr/include/x86_64-linux-gnu/bits/typesizes.h .. /usr/include/libio.h ... /usr/include/_G_config.h .... /usr/lib/gcc/x86_64-linux-gnu/4.7/include/stddef.h .... /usr/include/wchar.h ... /usr/lib/gcc/x86_64-linux-gnu/4.7/include/stdarg.h .. /usr/include/x86_64-linux-gnu/bits/stdio_lim.h .. /usr/include/x86_64-linux-gnu/bits/sys_errlist.h
每行开头的点表示嵌套的深度#include。
#include