CS 54 - Lab 0


Welcome

Hi everyone. Welcome to CS 54. This lab is designed to orient you with the systems we will be using here at UMR as well as how to handle common problems you may run into along the way. This is a very important lab, so keep up and don't hesitate to ask even the slightest question!


Filesystem Hierarchy

We will be working in a UNIX environment using a program called PuTTY. The UNIX filesystem, like the Windows filesystem consists of a hierarchy of directories, files, and links. The UNIX filesystem hierarchy is quite complex and you will have the opportunity to further explore it as you go along. Here are the parts of the hierarchy you should know for now:

PathComment
/"Slash" - the mother of the entire hierarchy. Everything can be traced back here.
/nethome/users/usernameusername's DFS drive. This is the same drive you see from Windows. This is where we'll be working and will be called "home."

There's lots more to explore, but we can discover that as we go along.


Connecting to UNIX machines

In order to work with the compiler for the rest of the semester, we will be using a program called PuTTY to connect to the UNIX machines. The name of the UNIX server is called gpunix.umr.edu. Type in gpunix.umr.edu as the hostname and click "Open":
[PuTTY Configuration]
If this question pops up, say yes:
[Key Verification]
After entering your username and password, your screen should look something like this:
[PuTTY Screen]

If the last line of the screen says bash-3.00$ and there are no glaring error messages, then you're in good shape. You are ready for the next part of the lab.


Working the UNIX Environment

We will be demonstrating and practicing all these commands in class, but here's a quick reference of each command we will use:

CommandComment
mkdir dirMakes a directory called dir.
pwdPrint Working Directory.
cd dirChange to directory dir.
cd ..Change to directory one directory above.
cd ../..Change to directory two directories above.
cd ~Change to your home directory.
cdChange to your home directory. Equivalent to the previous entry.
lsList files in the current directory.
ls -lList files in the current directory (Long Format).
cp source destCopy file source to destination file dest. The original file is preserved.
mv source destCopy file source to destination file dest. The original file is not preserved.
rm fileDelete file. Once a file is deleted, there is no way to get it back.
rmdir dirDelete directory dir. Once a directory is deleted, there is no way to get it back.
exitEnd your session and exit the UNIX system.

Using the jpico Editor

In order to create files in UNIX, you can use a file called a text editor. There are a myriad of text editors available for UNIX, Mac, Windows, et al. You can use whatever you are most comfortable with as long as you can get your work done. In this Lab, jpico will be the "official" editor we use. To start the jpico editor, type jpico file, where file is the name of the file you wish to edit. For instance, if I want to edit the file test.txt, I would type jpico text.txt and press <ENTER>. You can now start typing in jpico to create or edit your file. jpico has lots of commands you can use, but here's the important ones you should know:

CommandComment
^GShow/hide help.
^KDelete a line.
^OSave your work thus far.
^XQuit, with a chance to save.

Note that ^K means "Control + K" or "CTRL + K". That is, you press K while holding down the Control Key on your keyboard. There are many more commands that jpico supports. I'm sure you can learn these as we go along.


Working with the Compiler

We will now compile our first program. First, change to the lab00 directory by typing cd cs54/lab00. Second, use jpico to create a new file called lab00.cpp by typing jpico lab00.cpp. Then, put this text in the new file (WARNING: Do NOT copy & paste this code. Type it in!):

// Programmer: <Your Name>
// Class and Section: CS 54, Section <n>
// Date: January 9, 2007
// Purpose: Test the compiler & our jpico skills

#include <iostream>
using namespace std;

int main()
{
  cout << "Hello, world!" << endl;
  return 0;
}

Now we want to compile our C++ code into an actual program. The command to do this is:
g++ -Wall -W -s -pedantic-errors file.cpp -o executable
Wow! Only that, eh? Let's do this by parts:

PartComment
g++The GNU C++ Compiler. The actual program that converts our C++ code to something executable.
-Wall -W -s -pedantic-errorsThe compiler flags. These flags tell the compiler how to behave.
file.cppThe file you created that you want the compiler to compile.
-o executableTells the compiler to save the executable file in a file called executable

So, we will end up typing:
g++ -Wall -W -s -pedantic-errors lab00.cpp -o lab00
This will take lab00.cpp, compile it, and save the executable in a file named lab00.
If there are no errors, we can run the executable by typing:
./lab00
Our "hello, world" message will be printed out on the screen and we will be done...almost!


The Wonderful World of Compiler Error Messages

Now go to the line that ends in the text "endl". Delete the semi colon at the end of that line. Try to compile as we did above. See what happens? We get an error message from the compiler:
lab00.cpp: In function `int main()':
lab00.cpp:12: error: expected `;' before "return"

See how imperfect the compiler is? It indicates an error on line 12 (The line that has return 0;) but the error is actually on the line previous to line 12, which is line 11. This is a useful debugging technique when the compiler gives you an error. If you can't find the error the compiler thinks the error is on, try the line(s) before it instead. Compiler aren't perfect. Neither are we. Working through mistakes is what debugging is all about.