When you compile a program, the compiler usually operates in an orderly sequence of phases called passes. The sequence happens approximately like this:
- First, the compiler reads the source code, perhaps generating an intermediate code (such as pseudo-code) that simplifies the source code for subsequent processing.
- Next, the compiler converts the intermediate code (if there is any) or the original source code into an object code file, which contains machine language but is not yet executable. The compiler builds a separate object file for each source file. These are only temporary and are deleted by the compiler after compilation.
- Finally, the compiler runs a linker. The linker merges the newly-created object code with some standard, built-in object code to produce an executable file that can stand alone.
GNU environments use a simple command to invoke the C compiler:
gcc, which stands for "GNU Compiler Collection". (It used to
stand for "GNU C Compiler", but now GCC can compile many more
languages than just C.) Thus, to compile a small program, you will
usually type something like the following command:
On GNU systems, this results in the creation of an executable
program with the default name
a.out. To tell the compiler
you would like the executable program to be called something else,
-o option for setting the name of the object code:
gcc -o program_name file_name
For example, to create a program called
myprog from a file
gcc -o myprog myprog.c
To launch the resulting program
myprog from the same directory,