next up previous contents
Next: Error Checking and Warnings Up: Compiling with GCC Previous: Linking Object Files   Contents


Common Command-line Options

The list of command-line options gcc accepts runs to several pages, so we will only look at the most common ones in Table 1.2.

Table 1.2: GCC command-line options.
Option Description
-o FILE Specify the output filename; not necessary when compiling to object code. If FILE is not specified, the default name is a.out.
-c Compile without linking.
-DFOO=BAR Define a preprocessor macro named FOO with a value of BAR on the command-line.
-IDIRNAME Prepend DIRNAME to the list of directories searched for include files.
-LDIRNAME Prepend DIRNAME to the list of directories searched for library files. By default, gcc links against shared libraries.
-static Link against static libraries.
-lFOO Link against libFOO.
-g Include standard debugging information in the binary.
-ggdb Include lots of debugging information in the binary that only the GNU debugger, gdb, can understand.
-O Optimize the compiled code.
-ON Specify an optimization level N, $ 0<=N<= 3$.
-ansi Support the ANSI/ISO C standard, turning off GNU extensions that conflict with the standard (this option does not guarantee ANSI-compliant code).
-pedantic Emit all warnings required by the ANSI/ISO C standard.
-pedantic-errors Emit all errors required by the ANSI/ISO C standard.
-traditional Support the Kernighan and Ritchie C language syntax (such as the old-style function definition syntax). If you don't understand what this means, don't worry about it.
-w Suppress all warning messages. In my opinion, using this switch is a very bad idea!
-Wall Emit all generally useful warnings that gcc can provide. Specific warnings can also be flagged using -Wwarning.
-werror Convert all warnings into errors, which will stop the compilation.
-MM Output a make-compatible dependency list.
-v Show the commands used in each step of compilation.


next up previous contents
Next: Error Checking and Warnings Up: Compiling with GCC Previous: Linking Object Files   Contents
Cem Ozdogan 2007-05-16