THIS APPENDIX SUMMARIZES SOME OF THE more commonly used gcc
options. For information about all command-line options, under Unix, type the command man gcc
. You can also visit the gcc
Web site, http://gcc.gnu.org/onlinedocs, for complete online documentation.
This appendix summarizes the command-line options available in gcc
, release 3.3, and does not cover extensions added by other vendors, such as Apple Computer, Inc.
The general format of the gcc
command is
gcc [options] file [file ...]
Items enclosed in square brackets are optional.
Each file in the list is compiled by the gcc
compiler. Normally, this involves preprocessing, compiling, assembling, and linking. Command-line options can be used to alter this sequence.
The suffix of each input file determines the way the file is interpreted. This can be overridden with the –x
command-line option (consult the gcc
documentation). Table C.1 contains a list of common suffixes.
Table C.2 contains a list of common options used for compiling C programs.
Table C.2. Commonly Used gcc
Options
Option | Meaning | Example |
---|---|---|
| Displays summary of common command-line options. |
|
| Does not link the files, saves the object files using | gcc –c enumerator.c |
-dumpversion -g | Displays current version of gcc. Includes debugging information, typically for use with |
gcc –g testprog.c –o testprog |
| In the first case, defines the identifier
|
|
| Just preprocesses files and writes results to standard output; useful for examining the results of preprocessing. | gcc –E enumerator.c |
| Adds directory | gcc –I /users/ steve/include x.c |
| Resolves library references against the file specified by | gcc mathfuncs.c -lm |
| Adds directory | gcc –L /users/ steve/lib x.c |
| Places the executable file in the file named | gcc dbtest.c –o dbtest |
| Optimizes the code for execution speed according to the level specified by | gcc –O3 m1.c m2.c –o mathfuncs |
| Specifies the standard for C files.[1]
Use | gcc –std=c99 mod1.c mod2.c |
| Turns on warning messages specified by | 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. |
13.58.5.57