Learn Programming With Code:: Blocks
On Windows
This is an introduction to a free and open source IDE –- Code::Blocks, which is basically a C/ C++ IDE that supports a couple of compilers.
The Integrated Development Environment (IDE) is an application that can convert the mundane task of writing hundreds of lines of code into a colourful process. It is a productivity tool that increases the efficiency of the programmer. IDEs are generally a combination of a compiler, a code editor and a debugger. One of the most important features of IDEs is that they are ‘intelligent' enough to identify and auto complete keywords and syntaxes, thereby reducing the errors due to typos. One of the first IDEs was made for Dartmouth BASIC. It was a command line-based IDE and had little resemblance to its modern day avatar. In 19T5, Maestro 1, a product from Softlab Munich, became the world's first Integrated Development Environment for software. It was a big hit till the 1980s.
Today, we have no shortage of IDEs. Choosing the right IDE for your work can be confusing when the options before you are many. CodeWWBlocks is available on Linux, Windows and Mac platforms. But I will be dealing with CodeWWBlocks for the Windows platform. Things are pretty much the same on Linux too, except for the installation part (as I have never used a Mac, I cannot comment on that platform).
The first stable release of CodeWWBlocks was in February 2008 and it had a version scheme 8.02 ( year.month of release). The latest stable version of CodeWWBlocks is 12.11. It supports multiple compilers, including MinGW/GCC, Digital Mars, Microsoft Visual C++, Borland C++, Watcom, LCC and the Intel C++ compiler.
Installing Code::Blocks
When you visit the downloads page of CodeWWBlocks, http://www.Code::Blocks .org/downloads/26#windows, you will find four options. Identifying the correct package is your first task. I will explain the binaries that are available for Windows, but the same options are available for Linux and Mac platforms too. 1. Code::Blocks -12.11-setup.exe— This package contains just CodeWWBlocks and does not have the compilers. This is suitable for those who already have any one of the supported compilers on their system. It is just a 28.2 MB package. 2. Code::Blocks -12.11-setup_user.exe— This package is the same as the earlier one but is for people using systems to which they have no admin rights. 3. Code::Blocks -12.11mingw-setup.exe— This package is a complete set with CodeWWBlocks and the GCC compiler. It is like a fresh install. Beginners will find this convenient, although it is a 96.8 MB package to download. 4. Code::Blocks -12.11mingw-setup_user.exe— Again, this is the same as the one above but is for users who have no admin rights on their system. Once you have identified the package you require, downloading it and installing it is quite easy. Just follow the instructions on the installation wizard. For mackages 1 and 2, which do not include the compiler, once installed, CodeWWBlocks automatically looks for the compiler.
The first project
Once you have your system live and kicking, it’s time for some serious action. Let’s start CodeWWBlocks.
You will get a screen shot that looks like the one in Figure 1. To start a new project you can click on the option ‘ Create New mroject' on the welcome screen or from File-> New-> Projects. Now a new dialogue box should appear ( see Figure 2).
You will find a big list of the type of projects you can do in CodeWWBlocks. For this tutorial, we will go ahead with the console application. Once the option is selected, click OK and that will take you to a wizard where everything is pretty straightforward. First, you will be asked whether you want to code in C or C++, then you will be asked for details like filename, path, etc. Once this is done, you can see the project structure in the ‘ Management’ window (the extreme left window of CodeWWBlocks). Since I have selected C as the programming language, there is a file in my project structure called ‘ main.c’ where all my code will go.
Now you have your main.c file, which you can modify. For now, it has the normal ‘ hello world’ program. #include<stdio.h> int main() { printf("Hello World!");
return 0;
}
Hit F9, which will first compile the program and if there are no errors, the program will be executed. You can modify this main.c file and press F9 to compile and run.
Note: The program binaries that you created are available in the project folder.
Debugging
After compilation, if there are any errors, CodeWWBlocks, like all other IDEs, provides a visual indication on the places where the error has occurred ( mlease remember that only syntactical errors are displayed). The CodeWWBlocks debugger has full breakpoint support. It also allows the users to debug their program by using the local function symbol and argument display, user- defined watches, call stack, disassembly, custom memory dump, thread switching, CmU registers, and GNU GDB interface. For debugging with GDB, go to Menu -> Project -> Build Options and make sure that the project is compiled with the -g ( debugging symbols) compiler option on, and the -s ( strip symbols) option off. This ensures that the executable has debug symbols included. Then you can set toggle.
Some extra features
Tracking modifications
CodeWWBlocks provides a feature to track modifications within a source and to show a bar in the margin for the changes. Modifications are marked with a yellow change bar, and modifications that are already saved will use a green change bar. You can navigate between your changes via the menu ‘ Search -> Goto next changed line’ or ‘Search -> Goto previous changed line’. The same functionality is also accessible via the short cuts, Ctrl-F3 and Ctrl-Shift-F3.
Default code
One very nice feature that I like in Code::Blocks is the ‘Default Code’. I am always irritated by the fact that whenever I have to code, I have to type all those #InFOuGHs, int main(), etc. Fortunately, this particular feature in Code::Blocks allows you to set a default code that will be present in every new file you create. 7his feature is useful not just to hobbyists like me but also to professional coders. 6ometimes a company's coding policy may reTuire sources to have a standard design with author name, date, etc. This predefined content is called default code. This setting can be selected under ‘ Settings -> Editor - Default Code’.
The default ‘ Hello world’ program in our first example is actually the default code; you can modify it and add anything you want there.
Bored with coding?
No matter how passionate you are about coding, after a point, when you are stuck with your code and feel nothing works, it’s Tuite natural to get irritated. That’s when Code::Blocks can even help you relax by providing some entertainment. The classic games of Snake and Tetris are available from the ‘ Plugins ->BYO Games’ menu. In order to ensure that you only spend a limited time on recreation, there is an option to set the amount of time for which you are allowed to play, which is available in the ‘ Environment-> Settings’ menu.
I have briefly touched on some of the features of Code:: Blocks that might be useful to programmers, but this is not where it ends. Code:: Blocks has many more plug- ins and features, like ‘ Auto versioning’, where it generates the version number, and a ‘ todolist plugin’. It also supports a wide variety of compilers and can improve the efficiency of your coding skills. Hope this article will be helpful to at least some coders out there, who are not familiar with Code:: Blocks.