GNU Compiler Collection
To start talking about GCC (GNU Compiler Collection) we need to understand some concepts. First of all, let's talk about languages. A language is the method of communication, either spoken or written, consisting of the use of words in a structured and conventional way. If you want to communicate with someone who doesn’t speak your language, you can use a translator app or interpreter. But, what is an interpreter? In this case, is a professional who allows communication between two or more people.
The same concepts apply to computer science, specifically to programming. We need an interpreter or a compiler (both do the same job in different ways) which could understand our code (most of the time in a high-level language) and translates it to machine language.
Now we can talk about GCC or GNU Compiler Collection. As the name says is a collection of compilers, that means that GCC can translate different languages into machine language. That sounds too simple.
How does GCC work? GCC does 4 steps to compile a file, and I’m going to explain every step with the next example. We can suppose we have a source file called main.c. First of all, we need to type the next gcc main.c . And let the magic starts.
- Pre-processing: Source files are processed by removing comments, expansion of macros, expansion of headers (lines starting with #), and ending with a .i file; for this example, the output of pre-processing is a main.i file.
- Compiling: The main.i file is compiled to produce an intermediate file: main.s, which its content is assembly code.
- Assembling: The main.s file is turned into a main.o file by the assembler. The content of main.o is machine-level instructions.
- Linking: This is the final step. The linker arranges the machine code to allow functions can be called. It also adds pieces of instructions from libraries (the ones that were included at the header of our code). The output of this process is an a.out file that is our executable program.
We can do step by step with some flags for the gcc command, and check every output and its content. But for now, this is all we need to know about gcc command.