My First
Eclipse Experience (Fall 2008 Edition, for CSc 102)
This is
a quick tutorial on how to get started with the Eclipse C++ Integrated
Development Environment (IDE).
This
presentation is entirely tied to my lectures in CSc 102, Introduction to
Computing, at City College of New York in Fall, 2008. Even more particularly, it
is the technical part of what I do in the first lecture of the semester, on
August 28, and what the lab instructors may do in the first lab, on August 29.
At home . . .
In the
lab you don't need to do the first four steps; Eclipse is installed.
1.
Point your Web
browser at:
http://www.eclipse.org/downloads/ Click
on the link
Eclipse IDE
for C/C++ Developers (68 MB),
and choose Windows. Choose a mirror site; Columbia is nearby, but any other http
site will do.
2.
You will be
asked whether you want to Open the downloaded file or Save it. Choose Save, and
click on OK. You will be asked where you want to store the compressed (ZIP)
file. Save it to a folder on your C: drive. Why not call it
EclipseC++? But that’s up to you
3.
Right-click on
the Eclipse file name (eclipse-cpp-ganymede-win32.zip),
in the folder you just created. Pull down to WinZIP. Click on
Extract to Here. That will get you a folder named
Eclipse;
click on it. Finally, when you are ready, click on the file named
Eclipse.exe. This is what is meant by “clicking on the file name” in
step 5 below. Your mileage may vary! This step doesn’t always work the same
way even on my machine. Mouse around; try reasonable things. It’s a very
simple installation, compared with some software.
4.
You need to
create a “workspace” for Eclipse. Put it in your CS102 folder; call it anything
you please. I named mine
WorkspaceForTutorial.
5.
Everything else
is identical to what you do in the lab. Pick up with Step 7 below.
In the lab . . .
-
You need to create a “workspace” for Eclipse. Put it
in a folder in
C:\TEMP;
call it anything you please. I named mine
WorkspaceForTutorial. Everything about loading Eclipse has been done for
you; just click on the desktop icon to launch Eclipse.
-
When you click on the
eclipse.exe
icon or file name, you will first see (briefly) the image shown in Fig.1.
“Ganymede” is the code name for the 2008 version of Eclipse. (Ganymede is
the largest moon of Jupiter; previous versions of Eclipse were named Calisto
and Europa, two other moons of Jupiter.)

Fig. 1. The first thing you see when you launch Eclipse. This
disappears after a few seconds.
-
When the window of Fig. 1 disappears, you will be
taken to a dialog like that in Fig. 2. A default workspace address is shown,
but we don’t want that. Click on Browse and navigate to the workspace you
just created. Click on
OK. (Actually, I'd suggest you first create a
folder in
C:\temp
(or wherever you want on your own machine) named
102HW1
or whatever, and specify that when you start Eclipse. Before long you
are going to have lots of saved workspaces; put them somewhere you can find
them, and give them names that mean something to you.)

Fig. 2. The Workspace
Launcher dialog that you get when you open Eclipse. The address shows the result
after I browsed to a workspace on my hard drive.
-
Up comes the welcome screen; see Fig.3.

Fig.3.
The Eclipse welcome screen.
-
The icons at the left on this welcome screen (which
you see only when you launch Eclipse with an empty workspace) are as shown
in Figs 4a, b, c, and d. Explore them if and when you wish. Not needed to
get the first assignment done.




Figs
4a, b, c, d.
-
The icon on the far right says to go to work. See
Figure 5.

Fig 5.
Get to work!
-
After clicking on the Workbench icon or in the far
top-left tab, you will see a blank Eclipse workbench. See Fig 6. Your screen
layout may be slightly different. Not a problem. You may or may not see an
Outline View on the far right. If you do, click on the X in its title bar is
dismiss it. We don't need it for this exercise.

Figure
6. The Eclipse workbench.
-
Create a project: File/New/C++ Project. Click on Next.
Name it Lab1, or anything else you please. Leave all selections as they are,
and click Finish. See Figures 7 and 8.)

Figure
7. Creating a C++ project.

Figure
8. Continue creating a C++ project.
11b. If
you click on Next instead of Finish, you will see this; just click Finish:

Fig 11b.
The Select Configurations dialog. Ignore; just press Finish.
-
Right-click on the Lab1 name in the Project Explorer.
Click on New, then Source File. See Figure 9.

Figure
9. Creating a new source file.
-
You will be asked to give the new source file (your
program) a name. Your choice. I called it
MyFirst.cpp.
Note the
cpp file
extension, which you must type. (It means C++.) Click Finish. See Figure 10.

Fig 10.
Naming your new source file.
-
The editor window will show a C++ comment giving basic
documentation. Change “Dan” to your name, or, if appropriate, your team
number and names of your team members. See Figure 11. Always do this!

Fig 11.
The opening editor window. Change the “Dan,” unless that is your last name!
-
Copy the following text to the editor, below the
comment. Select all the text; press Control-C (copy); move to the editor
window; position the cursor below the comment; press Control-V (paste)
#include
<iostream>
using
namespace
std;
int
main()
{
cout << "Hi,
Mom!" <<
endl;
// Compute and
print the sum of the first ten integers
double
sum = 0;
for
(int
i = 1; i <= 10; i++)
sum += i;
cout << "The sum
of the integers from 1 to 10 is: " << sum;
return
0;
}
We’ll
talk about this a bit later; for now, let’s just watch it run. Figure 12 shows
what your editor window should look like now.

Fig 12.
The editor window after you copy the program text shown just above.
-
Let’s say you have a little trouble reading the
editor window on your machine. Let’s make the font bigger.
-
Click on Windows/Preferences. See Figure 13.
-
In the box at top left, replace “type filter text”
with “font.” The window changes to Figure 14, after I click on Colors and
Fonts.
-
Click on As C++ Editor Text Font etc. See Figure 15.
-
Click on Text Style
Bold
and Size
12. Click on
OK, and click on OK in the Preferences window. Your editor window text is
now 12 point bold. Don’t like it? Change it back, or change to something
else. (But don’t change the Courier New.)
-
This a small sample of the great flexibility available
in a wide range of topics in Eclipse.

Fig 12.
The Preferences window, under Window.

Fig 13.
The Preferences window after typing” font” into the text box at the top left.

Fig 14.
The font selection window, which we get by double-clicking on As C++ Editor
Text Font etc., or by clicking on As C++ Editor Text Font etc then clicking on
Change. You often have this kind of choice. Double-clicking is faster.
-
Compile and link your program by clicking on
Project and
pulling down to
Build Project.
If there are no errors in the program, and I don’t think there are, you will
get a brief message saying
Build complete for project
Lab1,
and giving the time the process required. (Ignore the rest of the message
for now.)
-
Run your program by clicking on
Run and pulling down to Run. Eclipse will check to see if
there have been any changes since you last compiled and recompile if so.
Either way, the program will run, with output:
Hi, Mom!
The sum of the integers from 1 to 10 is: 55
-
That is your introduction to Eclipse. Don’t be
discouraged if it seems like slow going. In a week or two you will be able
to do all the steps of this tutorial in a couple of minutes. Really.
-
This program uses small pieces of the first two
chapters of the text. But we can understand the basic ideas. Let’s look.
-
#include <iostream>
is a
preprocessor directive. It says to bring into our program a large body
of code that handles input from the keyboard and output to the console.
That’s really about all we have to know, for this course. (There is no
semicolon at the end of this line.)
-
using namespace
std;
(note the
semicolon) says names like
iostream will come from a standard collection of names. Just do it; there
will be more about this later in the course.
-
int main()
says that
main is a
function, and that it returns an integer. The parentheses are required;
in many cases the parentheses will contain information about data to be
processed by the function. Every program must have a
main function
somewhere; it’s where program execution begins.
-
The left curly brace on the next line denotes the
beginning of the body of the main function. The curly right brace at
the end of the program “closes” body, and is required. (The curly brace will
be at the end of the line above, with the default Eclipse settings. You can
change that—although I don’t know how at the moment.)
-
cout
is how we print output to the console. There is lots of talk in the text and
later in the course about what all can be written in a
cout
statement. Our output is a modified version of the first example in any
programming language:
Hello World! (cout
is pronounced "See Out.")
-
Next we have a comment, signaled by the two
slashes. This conveys no information to the compiler; it is for the benefit
of the (human) reader of the program.
IF YOU DON'T UNDERSTAND THE NEXT THREE STEPS, DON'T WORRY ABOUT IT!
I'M AHEAD OF THE TEXTBOOK.
-
double
sum = 0; is a
variable declaration. It says that
sum is
associated with a place in computer memory where a certain kind of number
can be stored.
sum is
initialized to zero.
-
The for (int i = 1; i <= 10; i++)
says to declare an integer variable
i
and initialize it to zero; execute the statement on
the next line as long as i is less than or equal to 10; add 1 to
i
each time around.
-
sum
+= i; says to
add the value
of i to
sum.
-
The
cout
does what it says it says
it does.
-
The curly right brace marks the end of the body of the
main function and the end of the program.
-
You’re done! When you are ready, tackle Homework 1
(HW1). You know just about everything needed to do it, with the help of
Chapters 1 and 2 of the text.
-
But if you don’t fully understand the program
please don’t
worry about it! The
for loop in particular will get considerably more
exposition in a couple of weeks.
Back to Dan McCracken's Home Page
The only
brand of chewing gum permitted in my classroom:
