What happens when you type gcc main.c.md

David Jesus Orozco Garcia
3 min readFeb 6, 2020

First of all, what is gcc? If we want to know What happens when you type gcc main.c, we need to know the base of all, gcc

GCC

GCC stands for GNU Compiler Collection ( produced by the GNUG nu is N ot U nix), that the name say, is a set of compilers for various languages. It provides all the infrastructure for building a entire software, like a front-end builder.

GCC is the way to convert a high level software that is understood by humans to a low level commands that is understood by a machine. In a gross mode, we can create a binary of our application

Features

  • Free
  • Sharable
  • Code source is open for modification

The question: What happens when you type gcc main.c?

We need to start to see our file so, in this example we are going to work with the next snippet

That snippet don’t have a relevant action, because in this post, we aren’t going to learn C, instead we are going to understand, the process behind the command gcc main.c

The process

The process is a union of 4 steps:

  1. Preprocessor (.c)
  2. Compilation (.i)
  3. Assembler (.s)
  4. Linker (.o) Are 4 but, in the 4, we just create the binary, not execute it.

1. Preprocessor

In this part, is the first program invoked by compiler and process directives like #include, #define and #if. That directives are not specifics of C. We can use it in any type of files If we want to create just this part, we need to execute the following

That line put the main.c just in the first step. So what happens?

2. Compilation

The words compilations means translate a programming language to a machine language, and we can do that with

gcc

3. Assembler

In this part, the assembly code generated before it’s going to be converted into a object code

gcc -c main.c; cat main.o

If you want to see, what is inside of the main.o object, you have to type

gcc -c main.c; objdump -d main.o

In this part our object, it’s going to be linked with other libraries that it require for be execute. The line of this depends of how many libraries with have to link

ld -o hello.exe hello.o ...libraries...

And that’s. This is the hard way to compile a main.c, because we can just type gcc main.c and do all the process with a output file call ( by default) a.out

Thanks

If you need help, don't dude to type me in my social media

Originally published at http://github.com.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

David Jesus Orozco Garcia
David Jesus Orozco Garcia

Written by David Jesus Orozco Garcia

Software enginner and current student at Uninorte

No responses yet

Write a response