Noeud:Basic Compilation Options, Noeud « Next »:, Noeud « Previous »:Overview, Noeud « Up »:GCC Commands



Basic Compilation Options

gcc can be invoked in it's simplest form using the command:

gcc [options] source.c

where source.c is the name of the source file. [options] can be any of the options given in the succeeding sections. This command compiles the source file and produces an executable file named a.out (due to historical reasons), providing there were no errors encountered in which case gcc will issue appropriate (or not as the case may be) error messages.

In this instance gcc preprocess the file and pipes it to the compiler; the compiler then produces a temporary file named source.s containing the assembly code; this is then passed to the assembler and the object file source.o is produced; finally, the executable a.out is produced after linking and temporary files (source.s and source.o) are removed.

The following examples assume the compilation of one file. In practice many files would be included, in which case more versatile command line options may sometimes be required. Including multiple files is easy; just list the files one after another. Invoking

gcc [options] source1 [[source2] ... [sourcen]]

will compile source1 and optionally source2 up to sourcen to produce the executable a.out, providing no errors occurred and all external symbols were satisfied. Listing multiple files can be done for any of the commands discussed below with regard to the different stages of compilation. In practice with larger projects one would use a makefile to manage multiple files - see GNU Make.

Although you may want to produce a binary most of the time, there are a number of options that enable you to stop at each different of the compilation. Each of these sections - preprocessing, compilation, assembly and linking - will be reviewed next, as well as some of the more well-used options.