The Compiler System GCC (GNU Compiler Collection) STEPS

Ahmed Belhaj
3 min readSep 16, 2020

--

What is it ? and how do you install it

GCC or Gnu Compiler Collection is a system software used in most GNU project and software and also the standard compiler for it and Linux also . In the beginning it was only for C programming language and named GNU C Compiler and got extended over time until reached multiple language such as c++, Objective-C, Fortran, Ada, Go, and D …

Installation Linux :

  • Open The Terminal and type

$ sudo apt-get install
  • check if installed and version
$ gcc --version
gcc (Ubuntu 7.2.0-18ubuntu2) 7.2.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

How does GCC work ?

The Steps

The compilation is a process of converting the source code into object code. It is done with the help of the compiler. The compiler checks the source code for the syntactical or structural errors, and if the source code is error-free, then it generates the object code. it convert the code from human readable language (C Programing language for example ) to binary and this processes composed from 4 Steps

1-Preprocessor

It is a stage when the compiler takes the source code and removes all of its comments that are indicated by a # or /**/. Source code is written in plain text and they’re saved as under .c file. also it get expanded (expand macro )

$ gcc -E namefile.c -o outputname

2-Compiler

The code you do by the preprocessor is passed to the compiler. The compiler converts this code into assembly code(human readable) . Or we can say that the C compiler converts the pre-processed code into assembly code.

$ gcc -c filename.c
Default output same name with .o

3-Assembler

This following stage is assembly that converts assembly code into an object code (machine language) which is then written into another file on the system. It is a way of translating into the specific machine instructions of the computer system. This format is in binary. After the program has been translated into this object code, it is ready to be linked.

$ gcc -S filename.c
Default output same name with .s

4-Linking

Mainly, all the programs written in C use library functions. These library functions are pre-compiled, and the object code of these library files is stored with ‘.lib’ (or ‘.a’) extension. The main working of the linker is to combine the object code of library files with the object code of our program. Sometimes the situation arises when our program refers to the functions defined in other files; then linker plays a very important role in this. It links the object code of these files to our program. Therefore, we conclude that the job of the linker is to link the object code of our program with the object code of the library files and other files. The output of the linker is the executable file. The name of the executable file is the same as the source file but differs only in their extensions. In DOS, the extension of the executable file is ‘.exe’, and in UNIX, the executable file can be named as ‘a.out’. For example, if we are using printf() function in a program, then the linker adds its associated code in an output file.

$ gcc filename.c -o outputname

--

--

Ahmed Belhaj

Dedicated DevOps Engineer with expertise in system administration, core development, and a full-stack software development.