The Eclipse Environment

[ Previous | 1 | 2 | Next ]

C++ (continued)

We have one of our two workspaces. We have our first project set up in that workspace. We have created a source file in that project. We are ready to test the compile, link and run. Note that Eclipse isn't doing anything "sneaky". If you check on the disk you'll find plain text files in sensible directories. You could transport those text files (.cpp and .h) to another platform and compile them there. (And Eclipse makes no entries in the registry.)

Type the following, time-honoured text into the funcMain.cpp edit pane:

If you said, "What about endl?", then full marks. I'm keeping it simple. And you could argue that endl's buffer flush is more expensive than you need. Equally you could argue that \n was a little bit platform dependent.

As you typed you may have seen red or yellow marks appearing and disappearing. These are some simple checks that the editor is doing on your C++ syntax. They can be useful. If the red marks haven't disappeared when you start a new code structure then you've probably made a punctuation or spelling mistake.

We are now ready to do a full compile. More red marks (errors) and yellow (warnings) marks may appear. C++ warnings should be treated as errors; they would often be errors in a less cavalier language.

To compile one or more selected files, select the files in the Explorer and right-mouse click on one of them. You will see Build Selected Files. If you want to compile everything and go onto linking them (if they compile), then right-mouse click on the project entry in the explorer where you will then see Build Project. Here is the latter:

There are other routes to this, via toolbar buttons, but they can be confusing, involving things called build and run configurations.

You should see some progress reports. And you should see a little progress guage at the very bottom right. If all has gone well and you are looking at the Problems tab of the output area at the bottom of Eclipse, it should be empty. If you have a warning, at the end of the file, it might be because g++ likes a blank line at the end of text files. If you are looking at the Console tab of the output area at the bottom, you should see this:

If a compile and link took place but reported errors, you should be able to correct the errors and get a clean compile and link (or "build" as it is known).

If you can't find the error, here is a version of the code that you can copy/paste:

#include <cstdlib>
#include <iostream>
using std::cout;

int main() {
cout << "Hello world\n";
return EXIT_SUCCESS;
}

If no compile or link took place, then your installation may have failed. If, for example, Eclipse complains about toolchains or the unavailability of g++, then your cygwin or mingw installation (on Windows) has failed. If you want to test cygwin on Windows, open up a DOS prompt (i.e. command prompt, command window, command.com, shell or however you know it) and try typing in bash (the Bourne again shell). You should see the bash prompt which of course would not be available under plain Windows:

Provided you weren't already using Eclipse, there are no worrying implications about deleting Eclipse and starting again. As far as Windows is concerned, it's all in one file tree and as I mentioned, it makes no registry entries. Remove the eclipse folder from Program Files or wherever you or your platform put Eclipse itself. And remove the workspace folder, AlicesRestaurant.

To complete the tests, close Eclipse, saying Yes to any Save questions. Then start it again.

You should now find your workspace listed in the drop-down list of the workspace chooser. Choose it.

You should see your project there where you left it.

Try it again with another new SecondGreeting project in your workspace. If that works and Eclipse remembers your workspace and the two projects within, then all is well.

If all has not gone well and a reinstallation has not worked, you could try seeking out a colleague. By now, every developer must know some other developer who is already an Eclipse user.

If you discover a mistake in these notes, do let me know.

Good luck,

See you on the course,

John

[ Previous | 1 | 2 | Next ]

[ Briefings Home Page | Training Courses from John Deacon | Books by John Deacon | JDL Home Page ]

Last modified: Friday December 04, 2009.
Copyright © 2009 John Deacon. All rights reserved.