Translation(s): none


Theory

GCC (GNU Compiler Collection) is a set of compilers developed by the GNU project that support a lot of languages, a lot of different architectures, and provides the basic layer for software development in most Free operating systems. GCC includes front ends for C, C++, Onjective C, Java, ADA and Fortran, although there are other non-standard front ends also available.

GCC is used to transform the source code of the programs into some executable binary files that can be understood by the computer. Programs coded in C usually have the extension ".c", while its header files usually end in ".h". Those coded in C++ might have extensions like ".cpp", ".cxx", ".cc" or just with a capital letter ".C". The extensions ".f" or ".for" belong to fortran, ".s" and ".S" to assembler code, and so on.

The general syntax for compiling a program with gcc is "gcc [ option | filename ]..." for programs in C, and "g++ [ option | filename ]..." for programs in C++

GCC supports many options, really a lot of them. The most commonly used are:

Exercises

Lets try to compile the simplest program in C. You can write it in your favourite editor, or just cat it directly from the console into a file (CTRL-D for EOF):

$ cat >test.c

Now we have a small C program in the file test.c, it doesn't matter too much if you don't understand it, don't worry.

Even though it's possible to compile it into a final executable in a single command, the process is really done in different phases, and it's quite usual to separate explicitly the compilation into binary objects (with the extension .o), and the final linking of these objects into a binary executable:

Compile the program:

Link the program:

Execute the program