What is a compiler?

Luisa Fernanda Pinillos Villa
3 min readJun 25, 2021

--

A compiler (gcc) traslates source code written in a high-level language like C or C ++ (human readable) into another language that the machine is capable of interpreting, creating an executable program. This “machine language” is very dificult or impossible for humans to read and understand, thus the need for high level languages such as C.

The term compiler was coined by American computer scientist Grace Hopper, who designed one of the first compilers in the early 1950s.

Grace Hopper

What is an executable file?

It’s a binary file. Its contain is interpreted by the computer as a program. This means it executes the code or a series of instructions contained in the file.

The steps are:

Compile process

1. Source file (file_name.c): The file contains the code written in high-level language.

2. Preprocessor: This program prepares or modifies the source code before being translated into binary code.

Preprocessed file (file_name.i).

3. Compiler: The program checks all kinds of limits, ranges, errors, etc. Before the compiler can successfully execute the code. The errors must be removed from the source code.

4. Assembler (File_name.s): An assembler ranslates assembly code to machine code.

The compiler and assembler are relevant in context to program execution. The compiler considers the entire code and converts it at the same time. Whereas, the assembler, converts the code line by line.

5. Linker: This program takes one or more object files (generated by a compiler or an assembler) and combines them into a single executable file, library file, or another “object” file.

6. Locator: Performs the conversion from relocatable program to executable binary.

7. Executable.

To compile you have to use this command:

gcc [program_name.c] –o [executable_name]

-o is the instruction for compiler. In the place [program_name.c], you have to write the name of the source file, ending in .c and in the place [executable_name], you have to write the finished file’s name.

To execute the program. Write:

./[executable_name]

Compile a program sequentially:

  • First create the source file (filename.c) and to run the file through the preprocessor, you have to use this command:
gcc -E file_name.c

The output file should be: file_name.i

  • The instruction to run the file through the assembler:
gcc -S file_name.c

The output file should be: file_name.s

  • To compile a file but don't link:
gcc -c file_name.c

The output file should be: file_name.o

Thank you for reading.

--

--