Using the GNU Compiler Collection (GCC): Directory Options

Next: Code Gen Options, Previous: Link Options, Up: Invoking GCC [Contents][Index]

### 3.15 Options for Directory Search

These options specify directories to search for header files, for libraries and for parts of the compiler:

`-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 vendor-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.

  If a standard system include directory, or a directory specified with `-isystem`, is also specified with `-I`, the `-I` option is ignored. The directory is still searched but as a system directory at its normal position in the system include chain. This is to ensure that GCC’s procedure to fix buggy system headers and the ordering for the `include_next` directive are not inadvertently changed. If you really need to change the search order for system directories, use the `-nostdinc` and/or `-isystem` options.

`-iplugindir=dir`

  Set the directory to search for plugins that are passed by `-fplugin=name` instead of `-fplugin=path/name.so`. This option is not meant to be used by the user, but only passed by the driver.

`-iquotedir`

  Add the directory dir to the head of the list of directories to be searched for header files only for the case of `#include "file"`; they are not searched for `#include <file>`, otherwise just like `-I`.

`-Ldir`

  Add directory dir to the list of directories to be searched for `-l`.

`-Bprefix`

  This option specifies where to find the executables, libraries, include files, and data files of the compiler itself.

  The compiler driver program runs one or more of the subprograms `cpp`, `cc1`, `as` and `ld`. It tries prefix as a prefix for each program it tries to run, both with and without ‘`machine/version/`’ for the corresponding target machine and compiler version.

  For each subprogram to be run, the compiler driver first tries the `-B` prefix, if any. If that name is not found, or if `-B` is not specified, the driver tries two standard prefixes, `/usr/lib/gcc/` and `/usr/local/lib/gcc/`. If neither of those results in a file name that is found, the unmodified program name is searched for using the directories specified in your `PATH` environment variable.

  The compiler checks to see if the path provided by `-B` refers to a directory, and if necessary it adds a directory separator character at the end of the path.

  `-B` prefixes that effectively specify directory names also apply to libraries in the linker, because the compiler translates these options into `-L` options for the linker. They also apply to include files in the preprocessor, because the compiler translates these options into `-isystem` options for the preprocessor. In this case, the compiler appends ‘`include`’ to the prefix.

  The runtime support file `libgcc.a` can also be searched for using the `-B` prefix, if needed. If it is not found there, the two standard prefixes above are tried, and that is all. The file is left out of the link if it is not found by those means.

  Another way to specify a prefix much like the `-B` prefix is to use the environment variable `GCC_EXEC_PREFIX`. See Environment Variables.

  As a special kludge, if the path provided by `-B` is `[dir/]stageN/`, where N is a number in the range 0 to 9, then it is replaced by `[dir/]include`. This is to help with boot-strapping the compiler.

`-no-canonical-prefixes`

  Do not expand any symbolic links, resolve references to ‘`/../`’ or ‘`/./`’, or make the path absolute when generating a relative prefix.

`--sysroot=dir`

  Use dir as the logical root directory for headers and libraries. For example, if the compiler normally searches for headers in `/usr/include` and libraries in `/usr/lib`, it instead searches `dir/usr/include` and `dir/usr/lib`.

  If you use both this option and the `-isysroot` option, then the `--sysroot` option applies to libraries, but the `-isysroot` option applies to header files.

  The GNU linker (beginning with version 2.16) has the necessary support for this option. If your linker does not support this option, the header file aspect of `--sysroot` still works, but the library aspect does not.

`--no-sysroot-suffix`

  For some targets, a suffix is added to the root directory specified with `--sysroot`, depending on the other options used, so that headers may for example be found in `dir/suffix/usr/include` instead of `dir/usr/include`. This option disables the addition of such a suffix.

`-I-`

  This option has been deprecated. Please use `-iquote` instead for `-I` directories before the `-I-` and remove the `-I-` option. Any directories you specify with `-I` options before the `-I-` option are searched only for the case of `#include "file"`; they are not searched for `#include <file>`.

  If additional directories are specified with `-I` options after the `-I-` option, these directories are searched for all `#include` directives. (Ordinarily all `-I` directories are used this way.)

  In addition, the `-I-` option inhibits the use of the current directory (where the current input file came from) as the first search directory for `#include "file"`. There is no way to override this effect of `-I-`. With `-I.` you can specify searching the directory that is current when the compiler is invoked. That is not exactly the same as what the preprocessor does by default, but it is often satisfactory.

  `-I-` does not inhibit the use of the standard system directories for header files. Thus, `-I-` and `-nostdinc` are independent.

Next: Code Gen Options, Previous: Link Options, Up: Invoking GCC [Contents][Index]