SE 333, Lab 2: Using Eclipse

The following are directions to run Xming, to run putty with X Windows enabled, to run eclipse off of the Computer Science and Software Engineering Linux box, which is named IO; to setup a C Makefile project in Eclipse and lastly to run and debug a C++ program.

Running (and installing if necessary) Xming

  1. Xming is an X Server for Microsoft Windows. It is needed to support connections to IO and to be able to use X programs like xman, xcalc, xclock, xterm, Eclipse etc. Computers in labs 206 and 217 have Xming already installed. If you need to install Xming on your personal machine, see

To run Xming in the labs, do the following: Start  All Programs  Computer Science  Xming (see the following diagram)

  1. Once this is done you will see the Xming icon in the icon tray.
  1. You can right-click on this icon to find out “about” Xming or exit from it. IT is VERY important that Xming is running to do the following steps.

Running putty

  1. Run putty: Start  All Programs  Applications  putty

Type in io.uwplatt.edu into the Host field:

  1. Click on the Keyboard item under Terminal and change the backspace key to Control-H:
  1. Expand the + in front of SSH:

  1. Click on X11, check the X11 forwarding check box and type into the X display location textbox : localhost:0

  1. Click the Open button and enter your system username and password.
  2. Now you should be able to run X commands. A simple test is to run xeyes:

The eyes will follow your mouse around – this is a simple test that X11 is working. You can close this by clicking on the red X; you may then get a warning about closing your X client session. If you do, click on the OK button.

  1. Let’s try another command. It’s generally a good idea to follow X11 commands with an ampersand ( & ) so as to run the program in the background. This then frees up your terminal session to give other commands. See both windows below where the Unix command “xcalc & “ was given. There may be warnings given in the Io window about missing fonts. If you do get warnings, you can hit the return key in the Io window to get the Unix prompt to reappear.

Running Eclipse on Io

  1. Enter the command: “eclipse &” from the Io prompt and click ok to the dialog asking about your workspace.
  1. When Eclipse starts, the first page will generally be blue with about five icons on it. Hover your mouse over them and click on the one with an arrow that says "Go to the workbench".
  2. The next step is to set up editor preferences so that code is formatted correctly. You only need to do this once.
  3. Select Window|Preferences
  4. Expand the General item by clicking on the triangle next to it.
  5. Expand Editors
  6. Click on "Text Editors"
  7. Check "Insert spaces for tabs"
  8. Change "Displayed tab width" to 3
    If you like, you can also turn on showing the print margin and line numbers.
  1. Expand "C/C++" (about half way down the list on the left)
  2. Select "Code Style" (under C/C++).
  3. Click on the Import... button
  4. You can browse to the correct location, but it's probably fastest to just type it in. Click on the pencil on paper icon and enter

/usr/local/eclipse/profiles/eclipse-uwp-cpp-profile.xml

  1. Click on the OK button.
  2. Once it's imported, make sure "UWP C++ General" is the selected profile:
  1. Scroll down to the Java item on the left-hand-side.
  2. Expand the Java entry, then “Code Style”.
  3. Click on “Formatter”.
  4. Import the style file

/usr/local/eclipse/profiles/eclipse-uwp-java-profile.xml

  1. Make sure the active profile is “UWP Java Baseline”.
  2. Click on the OK button to close the preferences window.

You should now be back at the main workbench.

  1. An important concept in Eclipse is the notion of a “perspective”. This consists of how the workbench is arranged for a particular class of projects. You can create your own perspectives, but for now we’ll just use the default one for C++. Your perspective is shown at the upper right corner and should currently be Java: The following steps show how to change it:
  2. Click on the Open Perspective button:
  3. Select “Other…”
  4. Select C/C++.
  5. Click on OK

The C/C++ perspective should be active. If it’s not, then the following directions won’t work for you.

Note that Eclipse is fully set up at this point, so you can exit any time you need to.

Greeting the world

The classic next step is to write a hello world program. Eclipse will even write it for you! Do the following:

  1. If you haven’t done so yet, check out your group repository to your home directory:

> cd

svn co file:///home/svn/se333X

> cd se333X/lab2

where X is your group identifier.

  1. If you have already checked it out, all you need to do is update:

> cd ~/se333X

svn update

> cd lab2

  1. In Eclipse, select File| New | C++ Project
  2. Set the project name to login-hellowhere login is your username.
  3. Clear the “Use default location” box and click on the Browse… button.
  4. Browse to the se333X/lab2 folder and create a folder with your login name:
  1. Click on OK.
  2. In the Project type window, expand “Makefile project” and click on “Hello World C++ Project”.

Caution: there are two hello world project items – you want the one under Makefile project.

  1. In the Toolchains window on the right, select Linux GCC.

You should now see something like the following:

  1. Click on the Next> button.
  2. Set the Author and copyright notice if you like.
  3. Change the greeting to something besides “Hello world”.
  4. Click on the Finish button. You should now be back at the Eclipse workbench.
  5. With the login-hello project selected on the workbench, click on the Run button
  6. Eclipse will prompt you for a configuration to run, select “gdb Debugger” as shown below. This is what will allow you to set breakpoints.
  1. Click on OK. Your program will run and the result shown in the Console window at the bottom of the screen:
  1. Use the Project Explorer on the left of the screen to open up your source code. You may be somewhat surprised to find C code in the file – this appears to be a bug. The indentation style is also not following the standard you already selected. Fix your program to use <iostream> instead of stdio and to use cout statements.
  2. Add a line after the output statement to print your name. Don’t forget the endl’s!
  3. Fix the indentation and put the braces in the right places.
  4. Remove the ‘void’ in main() – first, main actually accepts up to three parameters, and second the ‘void’ construct is a C-ism that isn’t appropriate for modern C++ programmers (or even ancient ones).
  5. Click on the hammer to re-build your solution. You can actually simply click on the run button, but this allows you to see how the program is being built. Note the Console window shows that g++ is being used to compile your program. You are now a Unix programmer.
  6. Run your program to make sure it works.
  7. Click on the line printing your name.
  8. Right click and select Toggle Breakpoint.
  9. Click on the bug icon to run your program in debug mode. When it prompts you for the launcher, click on “Change Workspace Settings…”.
  10. Under C/C++ Application, select “GDB (DSF) Create Process Launcher” and click on OK.
  11. Click on the OK button for the “Select Preferred Launcher” dialog.
  12. For the Save and Launch dialog, you probably want to check the “Always save resources before launching” box.
  13. The program will then run. You may get a prompt to confirm the perspective switch to the debug perspective; it would make sense to check in the “Remember my decision” box and then click on the Yes button.
  14. Step through and otherwise run your program until you get to the end.
  15. Click on the C/C++ perspective button to return to the editor.
  16. Make a trivial change to your program – perhaps a change to the documentation at the top or add some whitespace. Then save your solution, but do notrebuild it.
  17. Select File | Exit to exit eclipse. Note that clicking on the X in the upper right corner risks deleting your work.
  18. At the command-line prompt, cd to your directory:

> cd ~/se333X/lab2/login

Don’t forget to put in your group identifier and login name as appropriate.

  1. A nice thing about using Eclipse is that the build can be done from the command-line prompt. Enter

> make

You should then see build commands as before. Run your solution:

> ./login-hello

The ./ part means execute the command out of your current directory. Generally commands are run just by typing their names, but for commands not in the system directories you have to type in the path.

  1. Finally, add your work to the group repository so it can be graded. But first we want to get rid of the files that don’t need to be checked in. Type

> make clean

Now switch to the right directory, add the files, and commit the result:

> cd ../..

> svn add login

> svn commit –m “submitted lab2 solution"

Be sure to type the above commands in precisely – in particular make sure you get the right number of dots and use double quotes in the right places.

  1. Log out of Io by typing

logout

And you’re done!