oreilly.comSafari Books Online.Conferences.


Linux in a Nutshell

This directory of Linux commands is from Linux in a Nutshell, 5th Edition.

Click on any of the 687 commands below to get a description and list of available options. All links in the command summaries point to the online version of the book on Safari Bookshelf.

Buy it now, or read it online on Safari Bookshelf.


gcc [options] files

GNU Compiler Collection. gcc, formerly known as the GNU C Compiler, compiles multiple languages (C, C++, Objective-C, Ada, FORTRAN, and Java) to machine code. Here we document its use to compile C, C++, or Objective-C code. gcc compiles one or more programming source files; for example, C source files (file.c), assembler source files (file.s), or preprocessed C source files (file.i). If the file suffix is not recognizable, assume that the file is an object file or library. gcc normally invokes the C preprocessor, compiles the process code to assemble language code, assembles it, and then links it with the link editor. This process can be stopped at one of these stages using the -c, -S, or -E option. The steps may also differ depending on the language being compiled. By default, output is placed in a.out. In some cases, gcc generates an object file having a .o suffix and a corresponding root name.

Preprocessor and linker options given on the gcc command line are passed on to these tools when they are run. These options are briefly described here, but some are more fully described under entries for cpp, as, and ld. The options that follow are divided into general, preprocessor, linker, and warning options. gcc accepts many system-specific options not covered here.

Note: gcc is the GNU form of cc; on most Linux systems, the command cc will invoke gcc. The command g++ will invoke gcc with the appropriate options for interpreting C++.

General options


Provide profile information for basic blocks.

-aux-info file

Print prototyped declarations and information on their origins to file.


Enforce full ANSI conformance.

-b machine

Compile for use on machine type.


Create linkable object file for each source file, but do not call linker.


Print compiler's default target machine, then exit.


Print built-in specification strings, then exit.


Print version number, then exit.


Set the specified compiler option. Many of these control debugging, optimization of code, and special language options. Use the --help -v options for a full listing.


Include debugging information for use with gdb.


Provide level amount of debugging information. level must be 1, 2, or 3, with 1 providing the least amount of information. The default is 2.


Print most common basic options, then exit. When used with option -v, print options for all of gcc's subprocesses. For options specific to a target, use --target-help.


Set the specified machine specific option. Use the --target-help option for a full listing.

-o file

Specify output file as file. Default is a.out.


Provide profile information for use with prof.


On error, return highest error code as the exit code, instead of 1.


Warn verbosely.


Generate an error in every case in which -pedantic would have produced a warning.


Provide profile information for use with gprof.


Print the full path to the library specified by filename file, then exit. This is the library gcc would use for linking.


Print installation directory and the default list of directories gcc will search to find programs and libraries, then exit.


Transfer information between stages of compiler by pipes instead of temporary files.


Save temporary files in the current directory when compiling.


Specify C standard of input file. Accepted values are:

iso9899:1990, c89

1990 ISO C standard.


1994 amendment to the 1990 ISO C standard.

iso9899:1999, c99, iso9899:199x, c9x

1999 revised ISO C standard.


1990 C Standard with GNU extensions (the default value).

gnu99, gnu9x

1999 revised ISO C standard with GNU extensions.


Print statistics on the execution of each subprocess.


Verbose mode. Print subprocess commands to standard error as they are executed. Include gcc version number and preprocessor version number. To generate the same output without executing commands, use the option -###.


Suppress warnings.

-x language

Expect input file to be written in language, which may be c, objective-c, c-header, c++, ada, f77, ratfor, assembler, java, cpp-output, c++-cpp-output, objc-cpp-output, f77-cpp-output, assembler-with-cpp, or ada. If none is specified as language, guess the language by filename extension.


Specify the path directory in which the compiler files are located.


Preprocess the source files, but do not compile. Print result to standard output. This option is useful to meaningfully pass some cpp options that would otherwise break gcc, such as -C, -M, or -P.


Include dir in list of directories to search for include files. If dir is -, search those directories specified by -I before the -I- only when #include "file" is specified, not #include <file>.


Search dir in addition to standard directories.


Optimize. level should be 1, 2, 3, or 0 (the default is 1). 0 turns off optimization; 3 optimizes the most.


Compile source files into assembler code, but do not assemble.

-V version

Attempt to run gcc version version.


Pass options to the assembler. Multiple options are separated by commas.


Pass options to the linker. Multiple options are separated by commas.


Pass options to the preprocessor. Multiple options are separated by commas.

-Xlinker options

Pass options to the linker. A linker option with an argument requires two -Xlinkers, the first specifying the option and the second specifying the argument. Similar to -Wl.

Preprocessor options

gcc will pass the following options to the preprocessor:


Do not allow $ in identifiers.

-dD, -dI, -dM, -dN

Suppress normal output; print preprocessor instructions instead. See cpp for details.

-idirafter dir

Search dir for header files when a header file is not found in any of the included directories.

-imacros file

Process macros in file before processing main files.

-include file

Process file before main file.

-iprefix prefix

When adding directories with -iwithprefix, prepend prefix to the directory's name.

-isystem dir

Search dir for header files after searching directories specified with -I but before searching standard system directories.

-iwithprefix dir

Append dir to the list of directories to be searched when a header file cannot be found in the main include path. If -iprefix has been set, prepend that prefix to the directory's name.

-iwithprefixbefore dir

Insert dir at the beginning of the list of directories to be searched when a header file cannot be found in the main include path. If -iprefix has been set, prepend that prefix to the directory's name.


Search only specified, not standard, directories for header files.


Suppress searching of directories believed to contain C++-specific header files.


Convert special three-letter sequences, meant to represent missing characters on some terminals, into the single character they represent.


Suppress definition of all nonstandard macros.

-A name[=def]

Assert name with value def as if defined by #assert. To turn off standard assertions, use -A-.

-A -name[=def]

Cancel assertion name with value def.


Retain all comments except those found on cpp directive lines. By default, the preprocessor strips C-style comments.


Define name with value def as if by #define. If no =def is given, name is defined with value 1. -D has lower precedence than -U.


Print pathnames of included files, one per line, on standard error.

-M, -MG, -MF, -MD, -MMD, -MQ, -MT

Suppress normal output and print Makefile rules describing file dependencies. Print a rule for make that describes the main source file's dependencies. If -MG is specified, assume that missing header files are actually generated files, and look for them in the source file's directory. Most of these options imply -E. See cpp for further details.


Remove definition of symbol name.

Linker options

gcc will pass the following options to the linker:


Link to lib.


Force linker to ignore standard system startup files.


Suppress linking to standard library files.


Remove all symbol table and relocation information from the executable.


Create a shareable object.


Link to a shared version of libgcc if available.


Suppress linking to shared libraries.


Link to a static version of libgcc if available.

-u symbol

Force the linker to search libraries for a definition of symbol and to link to the libraries found.

Warning options


Warn verbosely.


Produce a fatal error in every case in which -pedantic would have produced a warning.


Don't print warnings.


Warn more verbosely than normal.


Warn if any functions that return structures or unions are defined or called.


Enable -W, -Wchar-subscripts, -Wcomment, -Wformat, -Wimplicit, -Wmain, -Wmissing-braces, -Wparentheses, -Wreturn-type, -Wsequence-point, -Wswitch, -Wtemplate-debugging, -Wtrigraphs, -Wuninitialized, -Wunknown-pragmas, -Wstrict-aliasing and -Wunused.


Warn when encountering instances in which pointers are cast to types that increase the required alignment of the target from its original definition.


Warn when encountering instances in which pointers are cast to types that lack the type qualifier with which the pointer was originally defined.


Warn when encountering arrays with subscripts of type char.


Warn when encountering the beginning of a nested comment.


Warn in particular cases of type conversions.


Exit at the first error.


Warn about inappropriately formatted printfs and scanfs.


Warn when encountering implicit function or parameter declarations.


Warn about illegal inline functions.


Warn about malformed main functions.


Enable more verbose warnings about omitted braces.


Warn if a global function is defined without a previous declaration.


Warn when encountering global function definitions without previous prototype declarations.


Warn if an extern declaration is encountered within a function.


Don't warn about use of #import.


Enable more verbose warnings about omitted parentheses.


Warn when encountering code that attempts to determine the size of a function or void.


Warn if anything is declared more than once in the same scope.


Warn about violations of sequence point rules defined in the C standard.


Warn about functions defined without return types or with improper return types.


Warn when a local variable shadows another local variable.


Insist that argument types be specified in function declarations and definitions.


Warn about switches that skip the index for one of their enumerated types.


Warn when encountering code that produces different results in ANSI C and traditional C.


Warn when encountering trigraphs.


Warn when encountering uninitialized automatic variables.


Warn when encountering a nonmacro identifier in an #if directive.


Warn when encountering a #pragma directive not understood by gcc.


Warn about unused variables, functions, labels, and parameters.

Pragma directives

#pragma interface [header-file]

Used in header files to force object files to provide definition information via references instead of including it locally in each file. C++-specific.

#pragma implementation [header-file]

Used in main input files to force generation of full output from header-file (or, if it is not specified, from the header file with the same basename as the file containing the pragma directive). This information will be globally visible. Normally the specified header file contains a #pragma interface directive.

Linux Resources
  • Linux Online
  • The Linux FAQ
  • Linux Kernel Archives
  • Kernel Traffic

  • Sponsored by: