Search Path - GCC 预处理器搜索路径

Search Path - GCC 预处理器搜索路径

https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html

By default, the preprocessor looks for header files included by the quote form of the directive #include "file" first relative to the directory of the current file, and then in a preconfigured list of standard system directories. For example, if /usr/include/sys/stat.h contains #include "types.h", GCC looks for types.h first in /usr/include/sys, then in its usual search path.
默认情况下,预处理器查找指令 #include "file" 的引用形式所包含的头文件,首先相对于当前文件的目录,然后查找预配置的标准系统目录列表。例如,如果 /usr/include/sys/stat.h 包含 #include "types.h",GCC 首先在 /usr/include/sys 中查找 types.h,然后按照惯例查找搜索路径。

For the angle-bracket form #include , the preprocessor’s default behavior is to look only in the standard system directories. The exact search directory list depends on the target system, how GCC is configured, and where it is installed. You can find the default search directory list for your version of CPP by invoking it with the -v option. For example,
对于尖括号形式 #include ,预处理器的默认行为是仅查看标准系统目录。确切的搜索目录列表取决于目标系统,GCC 的配置方式以及安装位置。您可以使用 -v 选项调用 CPP 版本的默认搜索目录列表。例如,

cpp -v /dev/null -o /dev/null

There are a number of command-line options you can use to add additional directories to the search path. The most commonly-used option is -Idir, which causes dir to be searched after the current directory (for the quote form of the directive) and ahead of the standard system directories. You can specify multiple -I options on the command line, in which case the directories are searched in left-to-right order.
您可以使用许多命令行选项将其他目录添加到搜索路径。最常用的选项是 -Idir,它导致在当前目录 (对于指令的引用形式) 之后和标准系统目录之前搜索 dir。您可以在命令行上指定多个 -I 选项,在这种情况下,将按从左到右的顺序搜索目录。

quote [kwəʊt]:vt. 引述,引用,举例说明,报价,以...为证,为 (企业的股份) 上市 vi. 引述,引用 n. 引文,语录,开价,(股票) 牌价,引号,(建筑或维修的) 报价单
directive [daɪ'rektɪv; dɪ'rektɪv]:n. 指示,指令 adj. 指导的,管理的

If you need separate control over the search paths for the quote and angle-bracket forms of the #include directive, you can use the -iquote and/or -isystem options instead of -I. See Invocation, for a detailed description of these options, as well as others that are less generally useful.
如果需要单独控制 #include 指令的引号和尖括号形式的搜索路径,可以使用 -iquote 和/或 -isystem 选项而不是 -I。有关这些选项的详细说明以及其他不太常用的选项,请参阅调用。

#include “…” search starts here: 首先搜索当前文件的目录,然后查找预配置的标准系统目录列表。
#include <…> search starts here: 预处理器的默认行为是仅查看标准系统目录。

If you specify other options on the command line, such as -I, that affect where the preprocessor searches for header files, the directory list printed by the -v option reflects the actual search path used by the preprocessor.
如果在命令行上指定其他选项 (例如 -I) 会影响预处理器搜索头文件的位置,则 -v 选项打印的目录列表将反映预处理器使用的实际搜索路径。

Note that you can also prevent the preprocessor from searching any of the default system header directories with the -nostdinc option. This is useful when you are compiling an operating system kernel or some other program that does not use the standard C library facilities, or the standard C library itself.
请注意,您还可以阻止预处理器使用 -nostdinc 选项搜索任何默认系统头目录。当您编译操作系统内核或其他不使用标准 C 库工具或标准 C 库本身的程序时,这非常有用。

1. cpp -v /dev/null -o /dev/null

strong@foreverstrong:~$ cat /etc/hostname
foreverstrong
strong@foreverstrong:~$
strong@foreverstrong:~$ echo LD_LIBRARY_PATH
LD_LIBRARY_PATH
strong@foreverstrong:~$
strong@foreverstrong:~$ echo $LD_LIBRARY_PATH
/usr/local/cuda-8.0/lib64:
strong@foreverstrong:~$
strong@foreverstrong:~$ cpp -v /dev/null -o /dev/null
Using built-in specs.
COLLECT_GCC=cpp
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.9' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9)
COLLECT_GCC_OPTIONS='-E' '-v' '-o' '/dev/null' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/5/cc1 -E -quiet -v -imultiarch x86_64-linux-gnu /dev/null -o /dev/null -mtune=generic -march=x86-64 -fstack-protector-strong -Wformat -Wformat-security
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/5/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-linux-gnu/5/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/5/:/usr/lib/gcc/x86_64-linux-gnu/5/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/5/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/5/:/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/5/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-E' '-v' '-o' '/dev/null' '-mtune=generic' '-march=x86-64'
strong@foreverstrong:~$

你可能感兴趣的:(Search,Path,GCC,预处理器搜索路径,C,-,GCC)