Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Table C.2 contains a list of common options used for compiling C programs.
| Option | Meaning | Example |
|---|---|---|
| --help | Displays summary of common command-line options. | gcc --help |
| -c | Does not link the files, saves the object files using .o for the suffix of each object file. | gcc –c enumerator.c |
-dumpversion
-g | Displays current version of gcc. Includes debugging information, typically for use with gdb (use –ggdb if multiple debuggers are supported). | gcc -dumpversion
gcc –g testprog.c –o testprog |
| -D id -D id=value | In the first case, defines the identifier id to the preprocessor with value 1. In the second case, defines the identifier id and sets its value to value. | gcc –D DEBUG=3 test.c |
| -E | Just preprocesses files and writes results to standard output; useful for examining the results of preprocessing. | gcc –E enumerator.c |
| -I dir | Adds directory dir to the list of directories to be searched for header files; this directory is searched before other standard directories. | gcc –I /users/ steve/include x.c |
| -llibrary | Resolves library references against the file specified by library. This option should be specified after the files that need functions from the library. The linker searches standard places (see the –L option) for a file named liblibrary.a. | gcc mathfuncs.c -lm |
| -L dir | Adds directory dir to the list of directories to be searched for library files. This directory is searched first before other standard directories. | gcc –L /users/ steve/lib x.c |
| -o execfile | Places the executable file in the file named execfile. | gcc dbtest.c –o dbtest |
| -Olevel | Optimizes the code for execution speed according to the level specified by level, which can be 1, 2, or 3. If no level is specified, as in –O, then 1 is the default. Larger numbers indicate higher levels of optimization, and might result in longer compilation times and reduced debugging capability when using a debugger like gdb. | gcc –O3 m1.c m2.c –o mathfuncs |
| -std=standard | Specifies the standard for C files.[1] Use c99 for ANSI C99 without the GNU extensions. | gcc –std=c99 mod1.c mod2.c |
| -Wwarning | Turns on warning messages specified by warning. Useful options are all, to get optional warnings that might be helpful for most programs, and error, which turns all warnings into errors, thereby forcing you to correct them. | gcc –Werror mod1.c mod2.c |
[1] The current default is gnu89 for ANSI C90 plus GNU extensions. Will be changed to gnu99 (for ANSI C99 plus GNU extensions) once all C99 features are implemented.