| An Introduction to GCC - for the GNU compilers gcc and g++ by Brian J. Gough, foreword by Richard M. Stallman Paperback (6"x9"), 144 pages ISBN 0954161793 RRP £12.95 ($19.95) "A wonderfully thorough guide... well-written, seriously usable information" --- Linux User and Developer Magazine (Issue 40, June 2004) Get a printed copy>>> |
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.
| ISBN 0954161793 | An Introduction to GCC - for the GNU compilers gcc and g++ | See the print edition |