How compile with GCC

Julian Alexander Jerez Caicedo
2 min readFeb 10, 2022

--

Before knowing how GCC compilation is done, we must know what it means.

The acronym GCC stands for GNU Compiler Collection and as its name indicates it is a collection of compilers and supports several languages.

It is a free software released under the GPL license and is also a key part of the GNU project. The original intention of GCC was to write a compiler for the GNU operating system, and it has been adopted as a standard compiler by most Unix-like operating systems, such as Linux, BSD, Mac OS X, etc.

GCC compilation process

Although we call GCC a C language compiler, the process from a C language source code file to an executable file is not just a compilation process, but the following four interrelated steps:

Preprocessing (preprocessing): GCC first calls the preprocessing program cpp to preprocess. During preprocessing, the include file and the precompiled declarations (e.g. macro definition, define, etc.) in the .c file are parsed and replaced with actual content.

Compilation: Then call the cc1 program to compile In this stage, the .i object file is generated according to the input file.

Assembly: The assembly process is for assembly language steps, calling the as program to make it work. In general, after preprocessing and assembly of .S files and .s files, object files with .o will be generated.

Link: Once all object files are generated, GCC calls ld to complete the final linking job. All object files are organized in the appropriate positions in the executable program and, at the same time, the library functions called by the program are also linked to the appropriate locations in their respective file libraries.

The command line to start this process is:
gcc -(option) <file name>.c

--

--