How is the process to Compile with GCC

GCC is a GNU Compiler Collection very important know his use to program in C

What is GNU?

What is GCC?

C, C++, Objective-C, Fortran, Java, and more.

The GCC compiler was written in C and accepts options and file names as arguments so that engineers can have absolute control over the compilation process.

$ man GCC

As you can see above there are many different options to pass into the GCC function and at the very end, you can see in @file and an infill. This just basically lets a programmer specify what file should be used as input and what file they would like to specify as their output file. Many advanced software projects utilize the output of one file as the input into another file to solve a task.

When you have ready your program in C you push compiler GCC to create the executable program but internally he has four steps that are:

PREPROCESSING

The lines in our code that begin with the “#” character are preprocessor directives. In our “HelloWorld.c” program the first preprocessor directive (#include <stdio.h>) requests a standard header file, stdio.h, to be included in our source file. If you use macros in your program, this is the stage where it gets substituted by the corresponding value. In our program, #define PRINT THIS “Hello World\n” is the macro and all occurrences of PRINT THIS will get substituted with the corresponding value, hereby the string “Hello World\n”

So in the preprocessor stage, those included header files and defined macros are expanded and merged within the source file to produce a transitory source file.

By using GCC's “-E” flag we can directly do the pre-processing operation.

COMPILER

By using the “-S” flag with gcc we can convert the preprocessed C source code into assembly language without creating an object file

ASSEMBLER

ASSEMBLER was one of the first software tools developed after the invention of the digital computer.

If there are any calls to external functions in the assembly code, the Assembler leaves the addresses of the external functions undefined, to be filled in later by the Linker.

The Assembler can be invoked as shown below. By using the “-c” flag in gcc we can convert the assembly code into machine-level code:

[bash]$ gcc -c HelloWorld.c -o HelloWorld.o

HelloWorld.o

The only thing we can explain by looking at the HelloWorld.o file is about the string ELF in the first line. ELF stands for executable and linkable format.

An object file and an executable file come in several formats such as ELF (Executable and Linking Format) and COFF (Common Object-File Format). For example, ELF is used on Linux systems, while COFF is used on Windows systems.

This is a relatively new format for machine-level object files and executables that are produced by GCC. Prior to this, a format known as a.out was used. ELF is said to be a more sophisticated format than a.out (We might dig deeper into the ELF format in some other future article).

If you compile your code without specifying the name of the output file, the output file produced has name ‘a.out’ but the format now have changed to ELF. It is just that the default executable file name remains the same.

LINKING

THANKS, EVERYONE!!

Philanthropic developer interested in the gaming industry, and software development