Contents Menu Expand Light mode Dark mode Auto light/dark mode
Using the GNU Compiler Collection 13.0.1 (experimental 20220101) documentation
Logo
Using the GNU Compiler Collection 13.0.1 (experimental 20220101) documentation
  • Copyright
  • Introduction
  • Programming Languages Supported by GCC
  • Language Standards Supported by GCC
    • C Language
    • C++ Language
    • Objective-C and Objective-C++ Languages
    • Go Language
    • D language
    • References for Other Languages
  • GCC Command Options
    • Description
    • Option Summary
    • Options Controlling the Kind of Output
    • Compiling C++ Programs
    • Options Controlling C Dialect
    • Options Controlling C++ Dialect
    • Options Controlling Objective-C and Objective-C++ Dialects
    • Options to Control Diagnostic Messages Formatting
    • Options to Request or Suppress Warnings
    • Options That Control Static Analysis
    • Options for Debugging Your Program
    • Options That Control Optimization
    • Program Instrumentation Options
    • Options Controlling the Preprocessor
    • Passing Options to the Assembler
    • Options for Linking
    • Options for Directory Search
    • Options for Code Generation Conventions
    • GCC Developer Options
    • Machine-Dependent Options
      • AArch64 Options
      • Adapteva Epiphany Options
      • AMD GCN Options
      • ARC Options
      • ARM Options
      • AVR Options
      • Blackfin Options
      • C6X Options
      • CRIS Options
      • C-SKY Options
      • Darwin Options
      • DEC Alpha Options
      • eBPF Options
      • FR30 Options
      • FT32 Options
      • FRV Options
      • GNU/Linux Options
      • H8/300 Options
      • HPPA Options
      • IA-64 Options
      • LM32 Options
      • LoongArch Options
      • M32C Options
      • M32R/D Options
      • M680x0 Options
      • MCore Options
      • MeP Options
      • MicroBlaze Options
      • MIPS Options
      • MMIX Options
      • MN10300 Options
      • Moxie Options
      • MSP430 Options
      • NDS32 Options
      • Nios II Options
      • Nvidia PTX Options
      • OpenRISC Options
      • PDP-11 Options
      • picoChip Options
      • PowerPC Options
      • PRU Options
      • RISC-V Options
      • RL78 Options
      • IBM RS/6000 and PowerPC Options
      • RX Options
      • S/390 and zSeries Options
      • Score Options
      • SH Options
      • Solaris 2 Options
      • SPARC Options
      • Options for System V
      • V850 Options
      • VAX Options
      • Visium Options
      • VMS Options
      • VxWorks Options
      • x86 Options
      • x86 Windows Options
      • Xstormy16 Options
      • Xtensa Options
      • zSeries Options
    • Specifying Subprocesses and the Switches to Pass to Them
    • Environment Variables Affecting GCC
    • Using Precompiled Headers
    • C++ Modules
  • C Implementation-Defined Behavior
    • Translation
    • Environment
    • Identifiers
    • Characters
    • Integers
    • Floating Point
    • Arrays and Pointers
    • Hints
    • Structures, Unions, Enumerations, and Bit-Fields
    • Qualifiers
    • Declarators
    • Statements
    • Preprocessing Directives
    • Library Functions
    • Architecture
    • Locale-Specific Behavior
  • C++ Implementation-Defined Behavior
    • Conditionally-Supported Behavior
    • Exception Handling
  • Extensions to the C Language Family
    • Statements and Declarations in Expressions
    • Locally Declared Labels
    • Labels as Values
    • Nested Functions
    • Nonlocal Gotos
    • Constructing Function Calls
    • Referring to a Type with typeof
    • Conditionals with Omitted Operands
    • 128-bit Integers
    • Double-Word Integers
    • Complex Numbers
    • Additional Floating Types
    • Half-Precision Floating Point
    • Decimal Floating Types
    • Hex Floats
    • Fixed-Point Types
    • Named Address Spaces
    • Arrays of Length Zero
    • Structures with No Members
    • Arrays of Variable Length
    • Macros with a Variable Number of Arguments.
    • Slightly Looser Rules for Escaped Newlines
    • Non-Lvalue Arrays May Have Subscripts
    • Arithmetic on void- and Function-Pointers
    • Pointer Arguments in Variadic Functions
    • Pointers to Arrays with Qualifiers Work as Expected
    • Non-Constant Initializers
    • Compound Literals
    • Designated Initializers
    • Case Ranges
    • Cast to a Union Type
    • Mixed Declarations, Labels and Code
    • Declaring Attributes of Functions
      • Common Function Attributes
      • AArch64 Function Attributes
      • AMD GCN Function Attributes
      • ARC Function Attributes
      • ARM Function Attributes
      • AVR Function Attributes
      • Blackfin Function Attributes
      • BPF Function Attributes
      • C-SKY Function Attributes
      • Epiphany Function Attributes
      • H8/300 Function Attributes
      • IA-64 Function Attributes
      • M32C Function Attributes
      • M32R/D Function Attributes
      • m68k Function Attributes
      • MCORE Function Attributes
      • MeP Function Attributes
      • MicroBlaze Function Attributes
      • Microsoft Windows Function Attributes
      • MIPS Function Attributes
      • MSP430 Function Attributes
      • NDS32 Function Attributes
      • Nios II Function Attributes
      • Nvidia PTX Function Attributes
      • PowerPC Function Attributes
      • RISC-V Function Attributes
      • RL78 Function Attributes
      • RX Function Attributes
      • S/390 Function Attributes
      • SH Function Attributes
      • Symbian OS Function Attributes
      • V850 Function Attributes
      • Visium Function Attributes
      • x86 Function Attributes
      • Xstormy16 Function Attributes
    • Specifying Attributes of Variables
    • Specifying Attributes of Types
    • Label Attributes
    • Enumerator Attributes
    • Statement Attributes
    • Attribute Syntax
    • Prototypes and Old-Style Function Definitions
    • C++ Style Comments
    • Dollar Signs in Identifier Names
    • The Character ESC in Constants
    • Determining the Alignment of Functions, Types or Variables
    • An Inline Function is As Fast As a Macro
    • When is a Volatile Object Accessed?
    • How to Use Inline Assembly Language in C Code
    • Alternate Keywords
    • Incomplete enum Types
    • Function Names as Strings
    • Getting the Return or Frame Address of a Function
    • Using Vector Instructions through Built-in Functions
    • Support for offsetof
    • Legacy __sync Built-in Functions for Atomic Memory Access
    • Built-in Functions for Memory Model Aware Atomic Operations
    • Built-in Functions to Perform Arithmetic with Overflow Checking
    • x86-Specific Memory Model Extensions for Transactional Memory
    • Object Size Checking Built-in Functions
    • Other Built-in Functions Provided by GCC
    • Built-in Functions Specific to Particular Target Machines
      • AArch64 Built-in Functions
      • Alpha Built-in Functions
      • Altera Nios II Built-in Functions
      • ARC Built-in Functions
      • ARC SIMD Built-in Functions
      • ARM iWMMXt Built-in Functions
      • ARM C Language Extensions (ACLE)
      • ARM Floating Point Status and Control Intrinsics
      • ARM ARMv8-M Security Extensions
      • AVR Built-in Functions
      • Blackfin Built-in Functions
      • BPF Built-in Functions
      • FR-V Built-in Functions
      • MIPS DSP Built-in Functions
      • MIPS Paired-Single Support
      • MIPS Loongson Built-in Functions
      • MIPS SIMD Architecture (MSA) Support
      • Other MIPS Built-in Functions
      • MSP430 Built-in Functions
      • NDS32 Built-in Functions
      • picoChip Built-in Functions
      • Basic PowerPC Built-in Functions
      • PowerPC AltiVec/VSX Built-in Functions
      • PowerPC Hardware Transactional Memory Built-in Functions
      • PowerPC Atomic Memory Operation Functions
      • PowerPC Matrix-Multiply Assist Built-in Functions
      • PRU Built-in Functions
      • RISC-V Built-in Functions
      • RX Built-in Functions
      • S/390 System z Built-in Functions
      • SH Built-in Functions
      • SPARC VIS Built-in Functions
      • TI C6X Built-in Functions
      • x86 Built-in Functions
      • x86 Transactional Memory Intrinsics
      • x86 Control-Flow Protection Intrinsics
    • Format Checks Specific to Particular Target Machines
    • Pragmas Accepted by GCC
    • Unnamed Structure and Union Fields
    • Thread-Local Storage
    • Binary Constants using the 0b Prefix
  • Extensions to the C++ Language
    • Vague Linkage
    • Function Multiversioning
    • Type Traits
    • C++ Concepts
    • Deprecated Features
    • Backwards Compatibility
    • When is a Volatile C++ Object Accessed?
    • Restricting Pointer Aliasing
    • C++ Interface and Implementation Pragmas
    • Where’s the Template?
    • Extracting the Function Pointer from a Bound Pointer to Member Function
    • C++-Specific Variable, Function, and Type Attributes
  • GNU Objective-C Features
    • GNU Objective-C Runtime API
    • +load: Executing Code before main
    • Type Encoding
    • Garbage Collection
    • Constant String Objects
    • compatibility_alias
    • Exceptions
    • Synchronization
    • Fast Enumeration
    • Messaging with the GNU Objective-C Runtime
  • Binary Compatibility
  • gcov—a Test Coverage Program
    • Introduction to gcov
    • Invoking gcov
    • Using gcov with GCC Optimization
    • Brief Description of gcov Data Files
    • Data File Relocation to Support Cross-Profiling
    • Profiling and Test Coverage in Freestanding Environments
  • gcov-tool—an Offline Gcda Profile Processing Tool
  • gcov-dump—an Offline Gcda and Gcno Profile Dump Tool
  • lto-dump—Tool for dumping LTO object files.
  • Known Causes of Trouble with GCC
    • Actual Bugs We Haven’t Fixed Yet
    • Interoperation
    • Incompatibilities of GCC
    • Fixed Header Files
    • Standard Libraries
    • Disappointments and Misunderstandings
    • Common Misunderstandings with GNU C++
    • Certain Changes We Don’t Want to Make
    • Warning Messages and Error Messages
  • Reporting Bugs
    • Have You Found a Bug?
    • How and Where to Report Bugs
  • How To Get Help with GCC
  • Contributing to GCC Development
  • Funding Free Software
  • The GNU Project and GNU/Linux
  • GNU GENERAL PUBLIC LICENSE
  • GNU Free Documentation License
  • Contributors to GCC
  • Indexes and tables
Back to top
Edit this page

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.

-Wno-undef#

Default setting; overrides -Wundef.

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

-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 Affecting GCC.

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.

Next
Options for Code Generation Conventions
Previous
Options for Linking
Copyright © 1988-2022 Free Software Foundation, Inc.
Made with Sphinx and @pradyunsg's Furo
Last updated on Nov 08, 2022