Thursday, January 26, 2012

Hello Eclipse

As a developer, you know that the first impression of a development framework is how easy it is to write "Hello, World." with Eclipse CDT as your IDE, because it provides a great plug-in that handles your project creation and management to greatly speed up your development cycles.

Ok, so lets start by opening Eclipse and creating new C++ project.

  • From the eclipse menu create new project, File --> New --> C++ Project
  • In the C++ Project dialog, put Project name as "HelloEclipse" & select Toolchain as "MinGW GCC" & press Finish.

Now we have to create a C++ file for us to write code into.

  • From the eclipse menu create new source file, File --> New --> Source File
  • In the new source file dialog, put the file name "main.cpp" and choose Template as "Default C++ source template" & press Finish.

Now lets put in some code to our source file

#include <iostream>
using namespace std;

int main() {
   cout << "Hello World!\n";
   return 0;

Build the project, from Eclipse menu do, Project --> Build All or (Ctrl+B)

Migrating from Visual Studio to Eclipse CDT

After working long with Mirosoft Visual Studio, it is usually very difficult to move on, work with an entirely new environment. I am too facing problems, no doubt Visual Studio is a wonderful tools, but I want to try with something new. I also work with some of the tools provided by Microchip & its just when I tried to download new IDE, I got to know they are moving on to Eclipse, wow! thats a big change, as far as I could recall, the IDE is based on Win32 & not Java. So, here I go, I decided to put away MSVC and use Eclipse CDT for the development work along with MinGW as compiler toolchain. I will also be using the GnuWin32, which is the collection of GNU utilities build to run on Windows platform natively.

The next part was to choose the opensource alternative for MFC, there are vaious to choose from, I loved Qt the most. Qt is known as a cross-platform graphical user interface toolkit. It is that, but it's also a toolkit for dealing with databases, file access, sockets, and much more. Qt is not only a concurrent of MFC. It is a full toolkit, with many features available in a simpler way than in MFC, and many that simply have no equivalent in MFC:

  • Controls: Qt is a graphical toolkit, so provides a rich set of graphical controls: labels, combo box, toggle buttons. Some of them are very sophisticated, like the listview which allow to have multi column list view with icons and toggle buttons.
  • XML: Qt provides classes to manipulate XML documents (using Sax2 or Dom). The tool is simple, powerful, complete and bug free.
  • Regular Expressions: Qt provides full support for perl-compatible regular expression. This goes far beyond the simple '?' and '*' meta-characters. Regular Expressions are a very powerful tool, to parse documents, to grep patterns inside documents, to build filters, to define masks for edit controls.
  • Multi-platform: Qt is multi-platform. It works on Windows (any of them), Unix (any of them), MacOs X and embedded platforms. You just have to recompile your code to get it working on a different platform. Except for the compiler adjustments (or limitations), you don't have to touch your code.
  • Template classes: Qt provides useful classes to handle lists, files, dictionnaries, strings, threads, etc. All of them are very powerful and very handy; more than the STL and the MFC equivalents.
  • Memory management: Qt has many facilities that makes memory management a no-brainer. Qt objects are automatically destroyed when their parent is destroyed. Many classes have an implicit sharing mechanism that relieves you from the pain of managing destruction and copy of these objects.
  • Network API: Qt features classes to help programming with Network programming: socket, dns, ftp, http.
  • Database API: Qt features classes for seamless database integration : Data aware wigets, database connection, SQL queries.
  • OpenGL API: Qt provides classes for seamless integration with OpenGL (3D accelearted) libraries.
  • Canvas: Qt provides classes optimised for handling quickly moving 2d objects, usually known as sprites.
  • Styles: It is possible to fully customize the rendering of all the Qt controls. That way, Qt emulates the style of all the available toolkits: Motif, MFC, NextStep, etc

To start with you need to download some of the tools as follows:

  • The latest build of Eclipse for C++ development, this includes CDT. Download from here.
  • Download and install the Qt build with MinGW from here.
  • Also install the Qt Integration Plugin for Eclipse, this will give you the liberty to play with Qt inside Eclipse.
  • Install the MinGW compiler, available from this location.
  • Download and install GnuWin32 packages available here.

Once you are all done with installations, you are all set to try the "Hello Eclipse !" tutorial.