Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

The GNU C Programming Tutorial - The compiler

Node:The compiler, Next:, Previous:Basic ideas, Up:Using a compiler



The compiler

When you compile a program, the compiler usually operates in an orderly sequence of phases called passes. The sequence happens approximately like this:

  1. First, the compiler reads the source code, perhaps generating an intermediate code (such as pseudo-code) that simplifies the source code for subsequent processing.
  2. 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.
  3. 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:

gcc file_name

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, use the -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 called myprog.c, write

gcc -o myprog myprog.c

To launch the resulting program myprog from the same directory, type

./myprog

 
 
  Published under free license. Design by Interspire