a cross-platfrom C++ development environment

Preface

Here’s a short description on a cross-platform development environment thatis used in the bio.display project. The main aims of this environment are:

  • provide a C++ development environment
  • allow for a cross-platform build chain
  • allow for editing using similar IDEs across supported platforms
  • allow for debugging across supported platforms
  • be standard compliant
  • use cross-platform libraries

Platform support for the current environment:

  • Linux – works
  • Windows – works
  • MacOS X – should work with limitations on the IDE (haven’t tried)

The environment currently contains the following libraries:

How it works

This development environment is based on the GNU gcc toolchain on all platforms. On Linux, this is given by default. On Windows, the MinGW gcc toolchain is used. On MacOS X, the official X-Code development packages uses gcc as well.

For the cross-platform build toolchian, Trolltech’s qmake is used, which is a tool created just for this purpose.

For the IDE, Eclipse CDT is used, which is a cross-platfrom C++ development IDE, and allows for debugging.

License

This environment comes currently with the GNU GPLv2 license, but versions with other licenses might follow (please ask). Keep in mind though that if you link against the open source version of Qt, you have to use the GNU GPL license.

Setting up

Linux

Preparation

Depending on the Linux distribution you use, make sure to have the following installed on your system by your favourite package manager:

  • the boost library, including development packages, version 1.35.0
  • Qt, including development packages, version 4.3
  • a Java runtime (as the Eclipse IDE is written in Java)

Download and install Eclipse CDT

Download Eclipse CDT for Linux from the Eclipse download area. Note that there are separate 32-bit and 64-bit versions available, chose the appropriate for your system. Extract the downloaded archive to a convenient location.

Download and install Qt Eclipse integration

Trolltech provides a Qt Eclipse integration package that comes in handy. Download the Linux version, and uncompress unto your Eclipse directory. Make sure to chose the 32-bit or the 64-bit version, according to your system.

Windows

Download and install Eclipse CDT

Download Eclipse CDT for Windows from the Eclipse download area. Extract the downloaded archive to a convenient location.

Download and install nuwen’s MinGW

Go to nuwen.net, and download his MinGW distribution. This is a fairly large zip file – uncompress it into a convenient location.

Download and install Qt

Download and install Qt version 4.3.5 for Windows compiled for gcc4, and unzip into a convenient location. This version is different from the official Qt opensource Windows binaries in that it was compiled under gcc4, which is ships with nuwen’s MinGW (see above). If you’re interested in how this compilation is done, see here.

Download and install Qt Eclipse integration

Trolltech provides a Qt Eclipse integration package that comes in handy. Download the Windows version, and uncompress unto your Eclipse directory.

Create batch file to start Eclipse with nuwen’s MinGW

Create a batch file that will start Eclipse that will use nuwen’s MinGW. The batch file looks something like this:

@echo off
set PATH=C:\MinGW\bin;%SystemRoot%\System32
echo "Starting Eclipse..."
C:\eclipse\eclipse --clean

TODO: add gdb installation description here

Getting sample projects

I’ve provided some sample projects that demonstrate a single application, or multiple applications and libraries with cross-dependencies. To get the source code, check out the subversion repository at this URL:

http://svn.tyrell.hu/bio.display/samples/

(If you’re unfamiliar with subversion, read up on the documentation. On Windows, download and install TortoiseSVN, a handy subversion client.)

Opening, compiling & running code

Start up Eclipse

Start up your Eclipse CDT IDE that you installed during the setup phase above. On Windows, run the batch file you created as the last step for preparations.

Initially, Eclipse will ask for a workspace directory where it will store some metadata. Just select a directory at a convenient location.

Import a project

In Eclipse, go to:

  • File->Import..
  • Qt->Qt Project
  • click Next
  • find the directory containing the checked out sources, and select a Qt project file, for example: samples/cross-platform-dev-env/src/hello-boost-opengl/hello_boost_opengl.pro
  • click Finish

During this process, Eclipse might ask for the version of Qt to use. Show the appropriate Qt directories:

  • on Linux
    • /usr/bin – for the binaries
    • /usr/include/qt4 – for the include files
  • on Windows
    • C:\Qt\4.3.5\bin – for the binaries
    • C:\Qt\4.3.5\include – for the include files

On Windows, Eclipse might ask for the MinGW environment to use. Here, browse and show the MinGW installed by the Qt installer itself, usually in C:\MinGW .

As a project is imported, compilation and linking will start automatically.

Run the application

In Eclipse, select: Run->Run… , and see the application run 🙂 Eclipse might as for a debugger configuration even though you’re not debugging at the time being. Select gdb/mi on Linux, and MinGW gdb on Windows.

Debug the application

In Eclipse, select: Run->Debug… , and see the application run while being debugged. Normally there will be a breakpoint set to the main() function, and naturally you can set breakpoints as you see fit.

On Windows, the Qt installer does not install the Qt debug libraries as a default, so you might have issues running the debug version of an application at first. To have Qt build its own debug libraries, select:

  • Start->Qt by Trolltech v4.3.5 (Open Source)->Qt 4.3.5 (Build Debug Libraries)

This takes some time, so have a tea meanwhile.

Leave a Comment

You must be logged in to post a comment.