Options for Directory Search#
These options specify directories to search for header files, for libraries and for parts of the compiler:
- -I dir, -iquote dir, -isystem dir, -idirafter dir#
Add the directory
dir
to the list of directories to be searched for header files during preprocessing.If
dir
begins with=
or$SYSROOT
, then the=
or$SYSROOT
is replaced by the sysroot prefix; see--sysroot
and-isysroot
.Directories specified with
-iquote
apply only to the quote form of the directive,#include "file"
. Directories specified with-I
,-isystem
, or-idirafter
apply to lookup for both the#include "file"
and#include <file>
directives.You can specify any number or combination of these options on the command line to search for header files in several directories. The lookup order is as follows:
For the quote form of the include directive, the directory of the current file is searched first.
For the quote form of the include directive, the directories specified by
-iquote
options are searched in left-to-right order, as they appear on the command line.Directories specified with
-I
options are scanned in left-to-right order.Directories specified with
-isystem
options are scanned in left-to-right order.Standard system directories are scanned.
Directories specified with
-idirafter
options are scanned in left-to-right order.
You can use
-I
to override a system header file, substituting your own version, since these directories are searched before the standard 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.The
-isystem
and-idirafter
options also mark the directory as a system directory, so that it gets the same special treatment that is applied to the standard system directories.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.
- -I-#
Split the include path. This option has been deprecated. Please use
-iquote
instead for-I
directories before the-I-
and remove the-I-
option.Any directories specified with
-I
options before-I-
are searched only for headers requested with#include "file"
; they are not searched for#include <file>
. If additional directories are specified with-I
options after the-I-
, those directories are searched for all#include
directives.In addition,
-I-
inhibits the use of the directory of the current file directory as the first search directory for#include "file"
. There is no way to override this effect of-I-
.
- -iprefix prefix#
Specify
prefix
as the prefix for subsequent-iwithprefix
options. If the prefix represents a directory, you should include the final/
.
- -iwithprefix dir, -iwithprefixbefore dir#
Append
dir
to the prefix specified previously with-iprefix
, and add the resulting directory to the include search path.-iwithprefixbefore
puts it in the same place-I
would;-iwithprefix
puts it where-idirafter
would.
- -isysroot dir#
This option is like the
--sysroot
option, but applies only to header files (except for Darwin targets, where it applies to both header files and libraries). See the--sysroot
option for more information.
- -imultilib dir#
Use
dir
as a subdirectory of the directory containing target-specific C++ headers.
- -nostdinc#
Do not search the standard system directories for header files. Only the directories explicitly specified with
-I
,-iquote
,-isystem
, and/or-idirafter
options (and the directory of the current file, if appropriate) are searched.
- -nostdinc++#
Do not search for header files in the C++-specific standard directories, but do still search the other standard directories. (This option is used when building the C++ library.)
- -Wcomment, -Wcomments#
Warn whenever a comment-start sequence
/*
appears in a/*
comment, or whenever a backslash-newline appears in a//
comment. This warning is enabled by-Wall
.
- -Wtrigraphs#
Warn if any trigraphs are encountered that might change the meaning of the program. Trigraphs within comments are not warned about, except those that would form escaped newlines.
This option is implied by
-Wall
. If-Wall
is not given, this option is still enabled unless trigraphs are enabled. To get trigraph conversion without warnings, but get the other-Wall
warnings, use-trigraphs -Wall -Wno-trigraphs
.
- -Wundef#
Warn if an undefined identifier is evaluated in an
#if
directive. Such identifiers are replaced with zero.
- -Wexpansion-to-defined#
Warn whenever
defined
is encountered in the expansion of a macro (including the case where the macro is expanded by an#if
directive). Such usage is not portable. This warning is also enabled by-Wpedantic
and-Wextra
.
- -Wunused-macros#
Warn about macros defined in the main file that are unused. A macro is used if it is expanded or tested for existence at least once. The preprocessor also warns if the macro has not been used at the time it is redefined or undefined.
Built-in macros, macros defined on the command line, and macros defined in include files are not warned about.
Note
If a macro is actually used, but only used in skipped conditional blocks, then the preprocessor reports it as unused. To avoid the warning in such a case, you might improve the scope of the macro’s definition by, for example, moving it into the first skipped block. Alternatively, you could provide a dummy use with something like:
#if defined the_macro_causing_the_warning #endif
- -Wno-endif-labels#
Do not warn whenever an
#else
or an#endif
are followed by text. This sometimes happens in older programs with code of the form#if FOO ... #else FOO ... #endif FOO
The second and third
FOO
should be in comments. This warning is on by default.
- -Wendif-labels#
Default setting; overrides
-Wno-endif-labels
.
- -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.
- -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 withoutmachine/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 yourPATH
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 appendsinclude
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 variableGCC_EXEC_PREFIX
. See Environment Variables Affecting GCC.As a special kludge, if the path provided by
-B
is[dir/]stageN/
, whereN
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 searchesdir/usr/include
anddir/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.