GCC — The steps to compile with it!

GCC is an optimizing compiler produced by GNU project that supports a great amount of programming languages, hardware architectures and OS. It was released in 1987 by Richard Stallman but back then its name was GCC 1.0 as it was only able to handle C programming language. However, it was extended that same year to compile C++ and other programming languages were introduced, developed and then added to GCC. Most of the operating system switched to GCC after its official release but nowadays, most of them have moved to the Clang compiler due to political and licensing reasons. However, it is still popular among Windows users.


As you might know by now compiling with GCC have some steps that we should follow in order to be able to use executables in our OS with no issues and we should always follow them in the correct order as it is explained below.


Basically, in this step it will get rid of all comments written in your source file as it is something irrelevant for the final executable. It will also include the header files codes (meaning the .h files that you included in the first lines of your source code). Also, all of your macros will be replaced.


In this step GCC compiler will take the file that was already processed in the previous step and then it will generate intermediate representation code also known as IR code and eventually, it will create a .s file. Bare in mind that other compilers might generate a file in this step. However, this is not the case with GCC and it’s the compiler we will talk about in this post.


More known as the unreadable step! Okay, jokes aside… In this step all your code will be translated and converted into machine language as in binary language (that’s why it will be unreadable by human eye). A .o file will be generated in this step.


La crème de la crème: in this step we’ve reached the very best step of it all as you’ll be generating your first executable in binary! However, we cannot conclude our post in such a simple and vague explanation. We wouldn’t get paid then. In this step, you will be merging all the source files together as in, your source code and the external libraries that you used in your source code. But if you need to code two different sources, you can combine them together in this step so that it will be part of your executable too.

After you’ve followed all these steps you will be generating your first executable so congratulations you’ve made it! But if you haven’t, GCC can be quite simple and all you need to do is to type the following command:

gcc filename.c

Obviously, you must replace filename.c with your own source code name and after you’ve done this, you will be generating another file named: a.out which is your first executable.

GCC also offers many options to compile a file that weren’t mentioned in this post as our main idea was to explain what does each step do and the why behind it. However, we kindly invite you to read its manual if you feel adventurous!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store