C/C++

Cross-Platform C/C++ Development with Eclipse CDT

By Ben Dupont, January 02, 2012

Using Eclipse as a universal C++ IDE for Linux and Windows requires navigating a few issues in setup and functionality. Here's how.

I've had to do a bit of cross-platform development for various projects over the years. For most of my development, my IDE of choice is Eclipse on Linux. To build in Windows, I create a new Visual Studio project and manually import the source files.
This works reasonably well for small, one-off projects, but it's a pain for larger projects that require regular modifications. One issue is that new files added to the Eclipse project must manually be imported to the Visual Studio project. Ideally, all changes made to the project in the Linux environment should be automatically realized in the Windows environment. Eclipse is a cross platform IDE, so this should be a snap, right? This article explores how to create one Eclipse project that can be used to compile on Windows using the Visual Studio compiler or on Linux using GCC, and share the source code via SVN. We'll also explore using a cross compiler on Linux to build a Windows executable. First, here's a bit on the environment.

Installation Woes

In both environments, I'm running 64-bit Eclipse Indigo with the plugins CDT, Subclipse, and SVNKit (included with Subclipse). Take a look at Figures 1 and 2 for version information. I previously tried Subclipse version 1.8 but couldn't get it to work with SVNKit. For Visual Studio, I'm using the 2010 Express Edition.

Figure 1: Eclipse Installation on Linux.

Figure 2: Eclipse plugins on Windows.

Installing Subclipse in Eclipse on Windows was problematic. Several times, I attempted to install by pointing to the URL, but the installation would pause indefinitely at around 30% complete. Downloading the zip file (site.1.6.18.zip) from the Subclipse website finally did the trick. However, I had to de-select the "SVN Revision Graph" option under "Subclipse" before the installation would work; the installer complained that the feature couldn't be found.

Once SVN was installed, a configuration step had to be completed under Linux and Windows: We need to tell the IDE which SVN library to use. By default, it tries to use the JavaHL library, which we didn't install. To change from JavaHL to SVNKit, browse to Window→Preferences. In the Preferences screen, expand Team and select SVN. Under "SVN Interface," select SVNKit and you'll see a screen similar to Figure 3.

Figure 3: Configuring Subversion.

Now the IDE is setup on Windows and Linux, and we can create a project. All the example projects will use the C++ source code shown in Listing One:

I first create a project under Windows and go through the process of configuring the Visual Studio toolchain. (We'll later look at porting the project to Linux, followed by creating an app under Linux and porting to Windows.)

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task.
However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Video

This month's Dr. Dobb's Journal

This month,
Dr. Dobb's Journal is devoted to mobile programming. We introduce you to Apple's new Swift programming language, discuss the perils of being the third-most-popular mobile platform, revisit SQLite on Android
, and much more!