Compiling Programs with gcc - Programming in C (Fourth Edition) (2015)

Programming in C (Fourth Edition) (2015)

C. Compiling Programs with gcc

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 website, http://gcc.gnu.org/onlinedocs, for complete online documentation.

This appendix summarizes the command-line options available in gcc, release 4.9, and does not cover extensions added by other vendors.

General Command Format

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.

Image

Table C.1 Common Source File Suffixes

Command-Line Options

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

Image

Image

Table C.2 Commonly Used gcc Options