The Eclipse Environment

[ Previous | 1 | 2 | Next ]

There is an update (04-Jan-2010) in the C++ section

There is a further update (17-Jan-2010) in the C++ section

The practical courses have been using Eclipse as their development platform for some time now. Eclipse is a software development framework whose most famous manifestations are probably the Java and the C/C++ programming environments; there are, however, many more languages now supported.

For various reason, we are now holding some of the STFC Grid PP Training practical courses at venues without PCs, with participants bringing their own laptops. The details of this scheme will have been emailed to you from Grid PP Training. If you are coming to one of these bring-your-own courses, you will need Eclipse installed, as detailed in the aforementioned email.

Those participants who leave it until the weekend before the course (or the evening before! or (the train journey to the course!!)) are on their own when they discover, as they will, that something isn't quite right with the installation.

You should check that your installation is working. And this is why this page is offered. As at December 2009, we are suggesting Eclipse 3.4, so that is what will be illustrated here. I only have the means to test the Linux and Windows setups. If you are using a Mac, it is particularly important that you thoroughly try out your installation well before attending the course. The following notes should still be helpful. Also, I do not have the means to test any 64-bit versions of operating systems. 64-bit Windows is known to have problems with Java and therefore Eclipse (even the C++ development environment is written in Java).

[Note to self: I must somehow get a Mac version of the library we use.]

C++

On the Mac and Linux platforms, all you need to do is install Eclipse and the CDT plugins. CDT is the C/C++ Development Tools plugins package. If you are only going to be doing C++, there is a download with everything combined. Go to www.eclipse.org for more information and the downloads. If you will be using Eclipse for several languages, you might prefer to download the classic Eclipse (which was and is for Java) and add the plugins like CDT yourself.

If you are on a Windows platform you have one more step to perform. Whereas the other two platforms supply standard C++ tools, Windows does not. You will need a "toolchain". There are other possibilities, but the only one I know anything about is cygwin. Your mileage may vary but normally you only need install the cygwin core, g++, gbd and make components. It's reasonably straightforward. (An entire cygwin is very large, so you'd want a very good internet connection before considering installing all of cygwin. However, if you're a Unix/Linux fan who's forced to use a Windows platform (then you've probably heard of cygwin already) you might find cygwin useful.) Go to www.cygwin.org for more information.

UPDATE (04-Jan-2010) Cygwin has changed. The latest version is 1.7 and it behaves differently to 1.5 (Don't ask me what happened to 1.6!) Cygwin 1.7 discovers its mount points differently to 1.5. If you've got cygwin 1.5 you should consider staying with that. When I tried installing a copy of Eclipse 3.4 plus CDT to a different laptop, one with a freshly-installed cygwin, Eclipse was unable to find the cygwin 1.7 toolchain. Now I'm not sure which combination of the following three steps resoved the problem, but here's what I did: I added user environment variables to 1) include c:\cygwin\bin in the PATH, and 2) to make CYGWIN_HOME c:\cygwin; I added the binutils package to cygwin (this is useful for quite a few other uses of cygwin anyway) in addition to g++, gdb and make; and I (gulp) exported the Cygnus Software registry entries from a working machine (using regedit) and merged them into the registry of the new machine using Merge from a right-mouse click on the exported .reg file. DO BE CAREFUL THAT YOU KNOW WHAT YOU'RE DOING BEFORE MESSING WITH THE REGISTRY. I am still getting a warning — possibly associated with cygwin whingeing about MS-DOS pathnames, but it is now working. (I wondered, but didn't try, if a later version of Eclipse might do better. Given that cygwin 1.7 came out in late December 2009, I suspect not.)

UPDATE (17-Jan-2010) Information is beginning to appear on the web as to what the problem is. I don't see that anyone has fully resolved it yet. (But you might.) One of the problems is that the scanner (responsible for as-you-type warnings) tries to execute G++ directly, whereas the makefile system goes through a shell. Because cygwin has changed the name of g++ from gcc.exe to gcc-3.exe, one approach works and the other doesn't. I'm not aggressively persuing a solution for Eclipse 3.4 because one possible outcome is that we start recommending Eclipse 3.5 (We stuck with Eclipse 3.4 because it wasn't broke so we didn't fix it; but now it is broken.)

Once everything is installed, start up Eclipse. It will ask you which workspace you want to use. A workspace is the major unit of organisation and is mostly a bunch of settings. Personally (on Windows at least) it irritates me that the default is something like MyDocuments. I would suggest changing to something else. In the courses, we will use workspaces as follows:

And it's convenient to be able to search and tidy up via one directory tree, so we normally put all of these workspace directories under one root directory. So, using Windows as an example, your screen should look something like this:

Don't tick the default box as it's usually convenient to be asked each time you start Eclipse.

Once you've clicked OK, Eclipse will continue starting up and may display a Welcome tab. Have a read of anything that looks interesting but eventually close the welcome tab. Then you should see something like this:

Look at the perspective near the top right:

Depending on the exact download you chose, Eclipse may start in the Java perspective. We want the C/C++ perspective. If it has started in C++, then fine. If there's a C/C++ button next to the Java button, then click it. Otherwise, click the Open Perspective button, the one with the yellow cross to the left of the tab. If you see C/C++ select it, otherwise go to Other… and select C/C++ from there. If there is no C/C++ to be found then you haven't carried out the correct downloads.

Once you've selected the C++ perspective, you should see something like this:

Then there are a couple of settings we usually change. Build (compile and link) Automatically works for Java; it doesn't work quite so well for C++, so we'll turn that off. And Save Automatically Before Build is usually desirable. Go to the Window menu and Preferences, open up the General branch, select the Workspace and reverse the two settings mentioned:

Now we need to set up a project. A project is the minor unit of organisation. A project has a product - an executable in our case. We will do each exercise in a project of its own. There are many kinds of projects (i.e. compiler switch settings that Eclipse will be looking after for us). It's important to get the right one. We will be using the simplest kind. Click the new project drop-down list button here:

Select the last one (usually) from the list — a C++ Project, then give it a name — FirstGreeting in this example, and then select an Executable / Empty Project, and click Finish (update: note the Cygwin GCC mentioned in the right-hand pane; if Eclipse can't find the cygwin toolchain (or any other toolchains) the toolchains list will be empty):

You should see a new project entry arrive in the left-hand Project Explorer pane:

Make sure that the project is selected (goes blue in my colour scheme even though it hasn't in the screen shot below) and then go to another New ... drop-down — the New Source File drop-down:

And select a Source File:

Call it funcMain.cpp and click Finish:

You should find that a new file is created on the disk in the workspace/project directory and an edit window should open up on this file. You are then ready to type in the time-honoured code …

[ Previous | 1 | 2 | Next ]

[ Briefings Home Page | Books by John Deacon | JDL Home Page ]