Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Command-Line Options

Command-Line Options

Table C.2 contains a list of common options used for compiling C programs.

Table C.2. Commonly Used gcc Options
OptionMeaningExample
--helpDisplays summary of common command-line options.gcc --help
-cDoes 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=valueIn 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
-EJust preprocesses files and writes results to standard output; useful for examining the results of preprocessing.
gcc –E
enumerator.c

-I dirAdds 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

-llibraryResolves 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 dirAdds 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 execfilePlaces the executable file in the file named execfile.
gcc dbtest.c –o
dbtest

-OlevelOptimizes 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=standardSpecifies the standard for C files.[1] Use c99 for ANSI C99 without the GNU extensions.
gcc –std=c99
mod1.c mod2.c

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


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial