11.1 An overview of the compilation process
The sequence of commands executed by a single invocation of GCC consists
of the following stages:
-
preprocessing (to expand macros)
-
compilation (from source code to assembly language)
-
assembly (from assembly language to machine code)
-
linking (to create the final executable)
As an example, we will examine these compilation stages individually
using the Hello World program 'hello.c':
#include <stdio.h>
int
main (void)
{
printf ("Hello, world!\n");
return 0;
}
Note that it is not necessary to use any of the individual commands
described in this section to compile a program. All the commands are
executed automatically and transparently by GCC internally, and can be
seen using the -v
option described earlier (see section 9.3 Verbose compilation). The purpose of this chapter is to provide an
understanding of how the compiler works.
Although the Hello World program is very simple it uses external
header files and libraries, and so exercises all the major steps of the
compilation process.