What happens when you type gcc main.c

What happens when you type gcc main.c

The GNU Compiler Collection (GCC) is a compiler system produced by the GNU Project supporting various programming languages. GCC is a key component of the GNU toolchain and the standard compiler for most projects related to GNU and Linux, including the Linux kernel. The Free Software Foundation (FSF) distributes GCC under the GNU General Public License General Public License (GNU GPL). GCC has played an important role in the growth of free software, as both a tool and an example.

But What happens when you type gcc main.c, it is divided into 4 things.

  1. Preprocessing
  2. Compiling 
  3. Assembling
  4. Linking

Preprocessing.

Preprocessing is the first step. The preprocessor obeys commands that begin with # (known as directives) by:

  • removing comments
  • expanding macros
  • expanding included files

If you included a header file such as #include <stdio.h>, it will look for the stdio.h file and copy the header file into the source code file.

The preprocessor also generates macro code and replaces symbolic constants defined using #define with their values.

Compiling

Compiling is the second step. It takes the output of the preprocessor and generates assembly language, an intermediate human readable language, specific to the target processor.

Assembling

Assembly is the third step of compilation. The assembler will convert the assembly code into pure binary code or machine code (zeros and ones). This code is also known as object code.

Linking

Linking is the final step of compilation. The linker merges all the object code from multiple modules into a single one. If we are using a function from libraries, linker will link our code with that library function code.

In static linking, the linker makes a copy of all used library functions to the executable file. In dynamic linking, the code is not copied, it is done by just placing the name of the library in the binary file.


To view or add a comment, sign in

More articles by Jhon Edison Arias Esparza

  • The future is now... IoT

    I can guess that at some point in your life you have had access to the internet either through cell phones, TVs…

  • Mutable, Immutable... everything is object!

    Python is an interesting programming language with a lot of features and utilities. It follows a work style…

  • A new world of object and class attributes

    Python is an object oriented programming language. Almost everything in Python is an object, with its properties and…

  • Differences between static and dynamic libraries

    What is a library? in C is the way for re-use code, the libraries can help us to do life very easy and a code more…

  • What happens when you type ls -l in the shell

    Let's start by explaining, what is a shell? is a program in charge of interpreting commands or in other terms it has…

    1 Comment
  • C static libraries

    A library is a collection of items that you can call from your program, you can save much time, A library is exactly…

  • What is the difference between a hard link and a symbolic link?

    In computing, a hard link is a directory entry that associates a name with a file on a file system. All directory-based…

  • learning command ls thoroughly

    The ls command is a command-line utility for listing the contents of a directory or directories given to it via…

Insights from the community

Others also viewed

Explore topics