Channels ▼
RSS

Web Development

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


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:

Listing One: A simple C++ program as an example.

#include <iostream>
include <list>

using namespace std;

int main()
{
	list<int> lst;

	lst.push_back(3);
	lst.push_back(1);
	lst.push_back(4);
	lst.push_back(1);
	lst.push_back(5);
	lst.push_back(9);
	lst.push_back(2);
	lst.push_back(6);
	lst.push_back(5);
	lst.push_back(3);

	lst.sort();

	cout << "sorted list: ";

	for (list<int>::iterator itr = lst.begin(); itr != lst.end(); itr++)
		cout << (*itr) << " ";

	cout << endl;

	return 0;
}

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.)


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

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.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 
Dr. Dobb's TV