Oh gee, it’s GCC

Alexandria Farrar
3 min readFeb 9, 2017

GCC stands for GNU Compiler Collection, that bundles several compilers and allows C, C++, Objective-C, Fortran, Java, and Ada and other languages to be compiled.

The compiler itself is comprised of three different parts, that we will interact with from the command line. These are the assembler, the compiler, the linker, the interpreter, and the loader.

To begin interacting with these parts from the shell, it’s important to have a basic C program. I created one called basiccommand.c that looks like this with emacs;

Which will simply print “Hello, Medium tutorials!”. Going back to the Shell,

We see the basiccomand.c exists as a C file, it is written in the C language.

Now, if we apply a basic “gcc” command, we see that an executable is created.

a.out is the executable file that we have now. If we want to get specific, we can run each part the of the gcc command to see what is going on as it does.

The first step in the gcc command is the preprocessor. That is the include<stdio.h> which points to the standard library of commands to be injected wherever you put that code. The preprocessor puts this code into the C code.

Want to know what it looks like?

The first command for just the preprocessor is cpp and has a file type “i”. If you want to save the isolated results of your preprocessor into a customized name, you’ll need a > which says place the resulting files in a file of this name and this type.

Now, you can emacs into your preprocessor file and see what’s in there. It will look something like this;

Next, once standard library commands are interpreted, the compiler now takes all that the preprocesser does and makes it executable.

We can see what that looks like by using the compiler’s specific command “cc” and its file type .s.

This will create an .s file of our original C file comprised of executable code if we run the cc comand through the .i file created from the last step.

Once that is done, we can can run it through all the parts of the compiler.

Insert your compiler “.s” code into your assembler code with the command aa and file type “.o”

What is an assembler? It takes the patterns of a computer and converts them into bits. Bits are what a computer can easily understand, and it is at this point that the command has been translated to low-level.

Finally run your “.o” file through your linker using command ld and it will print as was originally commanded by the C file. The linker takes all these files and puts them all into one executable file.

Now that we understand the parts of a compiler, I hope you are less intimidated by the concept and the steps it takes.

--

--

Alexandria Farrar

Writer, tech and science enthusiast, watercolor artist, activist. Proud cat mom. All the world’s a stage.