Friday, September 20, 2013

Code::Blocks - Install IDE, a C++ compiler and set it all up.

Aaaand it starts!
The first guide will be on Code::Blocks, a fantastic IDE that takes a lot of work off our shoulders, like any other IDEs do, but this one is free, open source and was designed for C++.

To start up, let's go check their download page:

You'll notice they have an installer for several OSs. If your OS counts with a repository, like Ubuntu does, all you need to do is install C::B through the software centre; and it will be piece of cake configuring the installation (it'll be automatic).

For you guys that use windows for your programming needs, you can go ahead to the C::B download page and get an installer file. There'll be two options, one with MinGW in the end of the file name and another without it. The difference is that one comes with the MinGW bundled in C::B while the other does not.

Step 1 - Download the latest binary release installer for C::B without MinGW on it's file name.
As of now, the file you are supposed to download is called codeblocks-12.11-setup.exe
Not codeblocks-12.11mingw-setup.exe

So, you got the file without MinGW. "Why download the one without the compiler if there's a bundled installer?" You'd be amazed on how many times I stumbled on this bundled compiler along my little journey. The best thing I done was starting to download MinGW separately, easier to update, maintain... This is specially true if you have any other IDEs that use MinGW.

This takes us to our next step.

Step 2 - Download the latest MinGW release installer from their own website.
From here:
The file at the time of this writing is called mingw-get-setup.exe

This installer is only around 84kb sized but don't be fooled. It is a web installer. It'll download everything necessary later. Later? Actually, if you are following the guide, it'll do it now.

Step 3 - Install MinGW.
The installer will look just like this:

Notice that I removed the shortcuts. Well, I see no use for them.
When you click continue MinGW will download itself and automatically install its base, the C++ compiler g++ and the Objective-C compiler.

After the download completes, it'll open up a window where you can tell it to install any additional packages you may need; I like to install the g++ documentation, just in case.

Here's a list of extra packages you should install:
  • msys-base
  • most up-to-date autoconf, automake and autogen bin packages (mingw32 and msys)
  • (optional) zlib, lua and other libraries
Specially msys-base, without it you'll have a hard time with some libraries. Installing libraries through here makes our lives easier, since they wont require linking nor building.

Sorry for the big images, but the reduced ones won't cut it.

If you don't need any extras or have already installed them, just close out of this window and MinGW is installed and working.

Now, it is wise to add MinGW to window's system variables, if it was not added automatically.
To do so, press "Super" (aka Windows Logo) + Pause Break and go through Advanced system settings -> Environment Variables... and then check if you have a MinGW entry there (image below).

If there is no variable called MINGDIR on your list, press New... and add it manually. Notice that c:/mingw is my install folder, if you installed it somewhere else, adjust it.

Now we have everything we need to compile g++ code. The hardest part is over.

Let's go ahead and set up our Environment, our IDE, Code::Blocks.

 Step 4 - Install Code::Blocks.

The installer will look like this:

As you can see, I removed the Shortcuts. I hate shortcuts.
The installation is pretty straight forward, there's no bloatware, not toolbar or McAfee uselesscan tool (Yeah Adobe, Oracle, Code::Blocks is way above you!).
Just hit next 'til success!

Once installed, run the IDE and it'll prompt you for a compiler. As we are using MinGW, you should choose GNU GCC Compiler. If it simply did not prompt you, go to Settings -> Compiler...

Verify that the compiler has probably been automatically selected. If it was not, select it manually.

And that's it for our installation!

You can try and compile a small Hello, World! program.

 #include <iostream>  
 int main () {  
   std::cout << "Hello world!" << std::endl;  
   return 0;  

Create a Console Application project, hit Build and Run and this is what you should have:

Until the next post!
Over and Out.

No comments:

Post a Comment