C/C++ for Hackers: Part 5 (More on the GNU GCC Compiler).

Part 5 (More on the GNU GCC Compiler).

Welcome back, fellow hackers! in this part of the series, we will talk a bit more about our favorite compiler: the GNU GCC compiler, and mostly it's extensive amount of functions. these functions allow us to optimise our software, making it run faster.

anyway, let's begin!

Step 1: Fire Up Ubuntu and Open the GCC Help Menu

first of all, we will startup our good friend Ubuntu, which as GCC already installed. when we have Ubuntu up and running, we will view the help page of GCC. To do this, enter the following in the terminal:

gcc --help

this should produce the following output:

we get a whole list of switches that can be used to compile our program, and i will go over the most important ones.

we can also get the manual page of GCC using this command:

man gcc

this will produce an immense output. the man page of GCC contains more than 5000 (!) lines, so obviously, we won't make a tutorial of all the switches in the GCC compiler.


this switch allows you to view help on specific areas of options. for example, if we check the optimizers field, we get this:

gcc --help=optimizers

this is my favourite part of the GCC compiler. as you can see, the -0fast tells our compiler to optimize our program for speed. we can also use -0g to set it to optimize it for debugging, and -0s to set it to optimize for space.


this simply tells you what version of GCC you are using. nothing much to it.

-B <directory>

this will tell the compiler to look into other directories other than it's root directory. you will probably need to invoke this command if you are going to use libraries that are not in GCC already.


one of the fun things in GCC is that you can choose to what layer the compiler reads. this option only does the pre process directives (the #include's).


this switch will do the same as the -E switch, except that it will do more: it will do the pre process directives, and then compile it to the assembly language (the only programming language that the CPU can understand directly). this can be useful for debugging.

-o <File>

this switch allows you to name the output file and also in which directory it is located. an usage example of this:

gcc -o SSHcracker.out main.c

this will tell our compiler to name the output file SSHcracker.out, and compile the main.c file.

-x <language>

this switch will simply allow you to choose the language to compile. GCC will do this automatically for you (it does this by looking at the file extension, .c is for C programs and .cpp is for C++ programs). but if you have an error, you could try specifying the language manually using this switch.


i know, this was a short tutorial, but hopefully, i explained the most basic commands for the GCC compiler well. also, i recommend that you read through the --help on your own if you have time. or if you REALLY have way too much time, you can look at the manual of GCC, but be aware, it's huge! (remember to use the --help=... switch to read info about a specific subject.)

also, thanks for the positive feedback on this series! in our next tutorial, we will take our first steps into C++, explain how to use C code in a C++ program, and we will talk about comment lines.



Cool post man. A nice addition to it would be to add some more usefull specific subjects that we can search with the --help=... switch.

Keep it up ma friend

well, it is displayed in the normal --help switch. this was also meant to be just a basic introduction to the GCC compiler and it's options.

and also, thanks for the support.


Thanks for the series, PHOENIX 750

i have just started with c++ (as you adviced) and this series is really helping me.


Thanks for the positive feedback. I'll try to restart this series soon.


Share Your Thoughts

  • Hot
  • Latest