Skip to content

Instantly share code, notes, and snippets.

@Lemmah
Last active September 15, 2019 18:19
Show Gist options
  • Save Lemmah/c6df957561bdc5b4723f4a6a2e171a78 to your computer and use it in GitHub Desktop.
Save Lemmah/c6df957561bdc5b4723f4a6a2e171a78 to your computer and use it in GitHub Desktop.
Steps from a C Program to an excutable binary.

Source code to Executable - C Program Steps

Understanding how gcc carries out its compilation

Let's start with a simple hello world program. Call it, hello_world.c . We're going to understand the process this little file with human readable text goes through to become a machine readable executable binary file. We will intentionally run the intermediate commands with gcc just to know what happens where.

1. Preprocessing

Takes all header files and includes them in source. Expands and inlines macros Strips out all comments

gcc -E -o hello_world_ext.c hello_world.c

2. Compilation

Semantic analysis Error checking Checks for and removes dead code

gcc -S hello_world_ext.c

3. Assembly

Converts it into an assembly object file.

gcc -c hello_world.s

4. Linking

Takes object file and combine with all libraries required to create an executable.

gcc -o hello_world hello_world.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment