Using Compiler Options

A compiler option is a case-sensitive, command-line expression used to change the compiler's default operation. Compiler options are not required to compile your program, but they are extremely useful in helping you control different aspects of your application, such as:

  • Code generation

  • Optimization

  • Output file (type, name, location)

  • Linking properties

  • Size of the executable

  • Speed of the executable

See Option Categories below for a broader view of the option capabilities included with the Intel® C++ Compiler.

Command-line Syntax (Linux* OS and OS X*)

When you specify compiler options on the command-line, the following syntax applies:

icc [options] [@response_file] file1 [file2...]                //Linux* and OS X* with EDG compiler
icl [options] [@response_file] file1 [file2...]      // OS X* with CLANG compiler

where options represents zero or more compiler options

where file is any of the following:

  • C or C++ source file (.C, .c, .cc, .cpp, .cxx, .c++, .i, .ii).

  • assembly file (.s, .S)

  • object file (.o)

  • static library (.a)

If you are compiling just C language sources, invoke the compiler with icc (for Linux* and OS X* ) or icc (for Linux*) or icl (for OS X*). You should invoke the compiler with icpc (for Linux* and OS X*) or icpc (for Linux*) or icl++ (for OS X*) if you are compiling just C++ language sources or a combination of C and C++.

Command-line Syntax (Windows* OS)

When you specify compiler options on the command-line, the following syntax applies:

icl [options] [@response_file] file1 [file2 ...] [/link linker_options]

where options represents zero or more compiler options.

where linker_options represents zero or more linker options.

where file is any of the following:

  • C or C++ source file (.c, .cc, .ccp, .cxx, .i)

  • assembly file (.asm),

  • object (.obj)

  • static library (.lib)

The optional response_file is a text file that lists compiler options you want to include during compilation. See Using Response Files.

The compiler reads command-line options from left to right. If your compilation includes competing options, then the compiler uses the one furthest to the right. In other words, "the last one wins." In this example:

// Linux* OS and OS X* with EDG compiler
icc -xP main.c file1.c -xW file2.c
// OS X* with CLANG compiler
icl -xP main.c file1.c -xW file2.c
// Windows* OS
icl /QxP main.c file1.c /QxW file2.c

the compiler sees [Q]xP and [Q]xW as two forms of the same option, where only one form can be used. Since [Q]xW is last (furthest to the right), it wins.

All options specified on the command line are used to compile each file. The compiler will NOT compile individual files with specific options as this example may suggest:

// Linux* OS and OS X* with EDG compiler
icc -O3 main.c file1.c -mp1 file2.c
OS X* with CLANG compiler
icl -O3 main.c file1.c -mp1 file2.c
// Windows* OS
icl /O3 main.c file1.c /Qprec file2.c

It may seem that main.c and file1.c are compiled with option O3, and file2.c is compiled with the -mp1 (Linux* OS and OS X*) or /Qprec (Windows* OS) option. This is not the case; all files are compiled with both options.

A rare exception to this rule is the -x type option:

// Linux* OS and OS X* with EDG compiler
icc -x c file1 -x c++ file2 -x assembler file3
// OS X* with CLANG compiler
icl -x c file1 -x c++ file2 -x assembler file3

where the type argument identifies each file type for the compiler.

Default Operation

The compiler invokes many options by default. For example, the O2 option is on by default for systems based on IA-32 architecture. In this simple example, the compiler includes option O2 (and the other default options) in the compilation:

// Linux* OS and OS X* with EDG compiler
icc main.c
// OS X* with CLANG compiler
icl main.c
// Windows* OS
icl main.c

See the Compiler Options reference for the default status of each compiler option.

Each time you invoke the compiler, options listed in the corresponding configuration file ( icl.cfg on Windows* OS or icc.cfg/icpc.cfg on Linux* OS and OS X* or or icc.cfg/icpc.cfg on Linux* OS or icl.cfg/icl++.cfg on OS X*) override any competing default options. For example, if your configuration file includes the O3 option, the compiler will use O3 rather than the default O2 option. Use the configuration file to list options for the compiler to use for every compilation. See Using Configuration Files.

Options specified in the CL environment variable override any competing default options and options listed in the configuration file.

Finally, options used on the command-line override any competing options specified elsewhere (default options, options in the configuration file, and options specified in the CL environment variable). If you specify option O1 on the command line, this option setting would "win" over competing option defaults and competing options in configuration files, in addition to competing options in the CL environment variable.

Certain #pragma statements in your source code can override competing options specified on the command line. For example, if a function in your code is preceded by #pragma optimize("", off), then optimization for that function is turned off, even though O2 optimization is on by default, O3 is listed in the configuration file, and O1 is specified on the command-line for the rest of the program.

Using Options with Arguments

Compiler options can be as simple as a single letter, such as option E. However, many options accept or require arguments. The O option, for example, accepts a single-value argument that the compiler uses to determine the degree of optimization. Other options require at least one argument and can accept multiple arguments. For most options that accept arguments, the compiler will warn you if your option and argument are not recognized. If you specify O9, the compiler will issue a warning, ignore the unrecognized option O9, and proceed with compilation.

While the O option does not require an argument, there are other options that must include an argument. The I option requires an argument that identifies the directory to add to the include file search path. If you use this option without an argument, the compiler will not finish compilation.

See the Compiler Options reference for a complete description of options and their supported arguments.

Other Forms of Options

You can toggle some options on or off by using the negation convention. For example, the [Q]complex-limited-range option (and many others) includes negation forms, -no-complex-limited-range (Linux* OS and OS X*) and /Qcomplex-limited-range- (Windows* OS), to change the state of the option. Since this option is disabled by default, using [Q]complex-limited-range on the command line would toggle it to the "ON" state.

Option Categories

When you invoke the Intel® C++ Compiler and specify a compiler option, you have a wide range of choices to influence the compiler's default operation. Intel® C++ Compiler options typically correspond to one or more of the following categories:

  • Advanced Optimization

  • Code Generation

  • Compatibility

  • Component Control

  • Data

  • Deprecated

  • Diagnostics

  • Floating Point

  • Help

  • Inlining

  • Interprocedural Optimizations (IPO)

  • Language

  • Linking/Linker

  • Miscellaneous

  • OpenMP* and Parallel Processing

  • Optimization

  • Output

  • Profile Guided Optimization (PGO)

  • Preprocessor

To see which options are included in each category, invoke the compiler from the command line with the help category option. For example:

icc -help codegen //Linux* and OS X* with EDG compiler
icl -help codegen //OS X* with CLANG compiler
icl /help codegen //Windows*

will print to stdout the names and syntax of the options in the Code Generation category.

For more complete information about compiler optimizations, see our Optimization Notice.