但是对于有些头文件存放位置,却不在通常的 /usr/include目录下,比如 stdarg.h
可以通过以下方式来查看 GCC编译时候所使用的默认搜索路径
首先,使用 gcc --help来查看 gcc支持的命令
点击(此处)折叠或打开
-
[martin@linux-2.6.11]$ gcc --help
-
Usage: gcc [options] file...
-
Options:
-
-pass-exit-codes Exit with highest error code from a phase
-
--help Display this information
-
--target-help Display target specific command line options
-
--help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,...]
-
Display specific types of command line options
-
(Use '-v --help' to display command line options of sub-processes)
-
--version Display compiler version information
-
-dumpspecs Display all of the built in spec strings
-
-dumpversion Display the version of the compiler
-
-dumpmachine Display the compiler's target processor
-
-print-search-dirs Display the directories in the compiler's search path
-
-print-libgcc-file-name Display the name of the compiler's companion library
-
-print-file-name=
Display the full path to library
-
-print-prog-name=
Display the full path to compiler component
-
-print-multiarch Display the target's normalized GNU triplet, used as
-
a component in the library path
-
-print-multi-directory Display the root directory for versions of libgcc
-
-print-multi-lib Display the mapping between command line options and
-
multiple library search directories
-
-print-multi-os-directory Display the relative path to OS libraries
-
-print-sysroot Display the target libraries directory
-
-print-sysroot-headers-suffix Display the sysroot suffix used to find headers
-
-Wa,<options> Pass comma-separated <options> on to the assembler
-
-Wp,<options> Pass comma-separated <options> on to the preprocessor
-
-Wl,<options> Pass comma-separated <options> on to the linker
-
-Xassembler <arg> Pass <arg> on to the assembler
-
-Xpreprocessor <arg> Pass <arg> on to the preprocessor
-
-Xlinker <arg> Pass <arg> on to the linker
-
-save-temps Do not delete intermediate files
-
-save-temps=<arg> Do not delete intermediate files
-
-no-canonical-prefixes Do not canonicalize paths when building relative
-
prefixes to other gcc components
-
-pipe Use pipes rather than intermediate files
-
-time Time the execution of each subprocess
-
-specs=<file> Override built-in specs with the contents of <file>
-
-std=<standard> Assume that the input sources are for <standard>
-
--sysroot=<directory> Use <directory> as the root directory for headers
-
and libraries
-
-B <directory> Add <directory> to the compiler's search paths
-
-v Display the programs invoked by the compiler
-
-### Like -v but options quoted and commands not executed
-
-E Preprocess only; do not compile, assemble or link
-
-S Compile only; do not assemble or link
-
-c Compile and assemble, but do not link
-
-o
Place the output into
-
-pie Create a position independent executable
-
-shared Create a shared library
-
-x
Specify the language of the following input files
-
Permissible languages include: c c++ assembler none
-
'none' means revert to the default behavior of
-
guessing the language based on the file's extension
-
-
Options starting with -g, -f, -m, -O, -W, or --param are automatically
-
passed on to the various sub-processes invoked by gcc. In order to pass
-
other options on to these processes the -W<letter> options must be used.
-
-
For bug reporting instructions, please see:
-
<file:///usr/share/doc/gcc-4.8/README.Bugs>.
- [martin@linux-2.6.11]$
其中有个 print-search-dirs,会罗列以下的搜罗目录,包括lib,.h文件等等(对比后发现是有重复的)
点击(此处)折叠或打开
-
[martin@linux-2.6.11]$ gcc -print-search-dirs
-
install: /usr/lib/gcc/i686-linux-gnu/4.8/
-
programs: =/usr/lib/gcc/i686-linux-gnu/4.8/:/usr/lib/gcc/i686-linux-gnu/4.8/:/usr/lib/gcc/i686-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.8/:/usr/lib/gcc/i686-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.8/../../../../i686-linux-gnu/bin/i686-linux-gnu/4.8/:/usr/lib/gcc/i686-linux-gnu/4.8/../../../../i686-linux-gnu/bin/i386-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.8/../../../../i686-linux-gnu/bin/
-
libraries: =/usr/lib/gcc/i686-linux-gnu/4.8/:/usr/lib/gcc/i686-linux-gnu/4.8/../../../../i686-linux-gnu/lib/i686-linux-gnu/4.8/:/usr/lib/gcc/i686-linux-gnu/4.8/../../../../i686-linux-gnu/lib/i386-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.8/../../../../i686-linux-gnu/lib/../lib/:/usr/lib/gcc/i686-linux-gnu/4.8/../../../i686-linux-gnu/4.8/:/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.8/../../../../lib/:/lib/i686-linux-gnu/4.8/:/lib/i386-linux-gnu/:/lib/../lib/:/usr/lib/i686-linux-gnu/4.8/:/usr/lib/i386-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/i686-linux-gnu/4.8/../../../../i686-linux-gnu/lib/:/usr/lib/gcc/i686-linux-gnu/4.8/../../../:/lib/:/usr/lib/
- [martin@linux-2.6.11]$
头文件的搜索,可以直接使用 -print-prog-name=
1. 对于 c的头文件,使用-print-prog-name=cc1
2. 对于c++的头文件, 使用 -print-prog-name=cc1plus
如果直接使用 gcc -print-prog-name=cc1,会打印 cc1的程序路径,比如
点击(此处)折叠或打开
-
[martin@linux-2.6.11]$ gcc -print-prog-name=cc1
-
/usr/lib/gcc/i686-linux-gnu/4.8/cc1
-
[martin@linux-2.6.11]$
-
[martin@linux-2.6.11]$ gcc -print-prog-name=cc1plus
-
/usr/lib/gcc/i686-linux-gnu/4.8/cc1plus
- [martin@linux-2.6.11]$
执行的方式有两种:
1. 直接执行该文件
2. 借助shell中的 `来实现 gcc -print-prog-name=cc1的程序
点击(此处)折叠或打开
-
[martin@linux-2.6.11]$ `gcc -print-prog-name=cc1` -v
-
ignoring nonexistent directory "/usr/lib/gcc/i686-linux-gnu/4.8/../../../../i686-linux-gnu/include"
-
#include "..." search starts here:
-
#include <...> search starts here:
-
/usr/lib/gcc/i686-linux-gnu/4.8/include
-
/usr/local/include
-
/usr/lib/gcc/i686-linux-gnu/4.8/include-fixed
-
/usr/include
-
End of search list.
-
^C^C
-
[martin@linux-2.6.11]$
-
[martin@linux-2.6.11]$ /usr/lib/gcc/i686-linux-gnu/4.8/cc1 -v
-
ignoring nonexistent directory "/usr/lib/gcc/i686-linux-gnu/4.8/../../../../i686-linux-gnu/include"
-
#include "..." search starts here:
-
#include <...> search starts here:
-
/usr/lib/gcc/i686-linux-gnu/4.8/include
-
/usr/local/include
-
/usr/lib/gcc/i686-linux-gnu/4.8/include-fixed
-
/usr/include
-
End of search list.
-
^C
-
[martin@linux-2.6.11]$
-
[martin@linux-2.6.11]$
-
[martin@linux-2.6.11]$ `gcc -print-prog-name=cc1plus` -v
-
ignoring nonexistent directory "/usr/lib/gcc/i686-linux-gnu/4.8/../../../../i686-linux-gnu/include"
-
#include "..." search starts here:
-
#include <...> search starts here:
-
/usr/include/c++/4.8
-
/usr/include/i386-linux-gnu/c++/4.8
-
/usr/include/c++/4.8/backward
-
/usr/lib/gcc/i686-linux-gnu/4.8/include
-
/usr/local/include
-
/usr/lib/gcc/i686-linux-gnu/4.8/include-fixed
-
/usr/include
-
End of search list.
-
^C
-
[martin@linux-2.6.11]$
-
[martin@linux-2.6.11]$ /usr/lib/gcc/i686-linux-gnu/4.8/cc1plus -v
-
ignoring nonexistent directory "/usr/lib/gcc/i686-linux-gnu/4.8/../../../../i686-linux-gnu/include"
-
#include "..." search starts here:
-
#include <...> search starts here:
-
/usr/include/c++/4.8
-
/usr/include/i386-linux-gnu/c++/4.8
-
/usr/include/c++/4.8/backward
-
/usr/lib/gcc/i686-linux-gnu/4.8/include
-
/usr/local/include
-
/usr/lib/gcc/i686-linux-gnu/4.8/include-fixed
-
/usr/include
-
End of search list.
-
^C
- [martin@linux-2.6.11]$