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!
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:
| Path | Comment |
| / | "Slash" - the mother of the entire hierarchy. Everything can be traced back here. |
| /nethome/users/username | username'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.
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]](putty_config.png)
If this question pops up, say yes:
![[Key Verification]](putty_key.png)
After entering your username and password, your screen should look something like this:
![[PuTTY Screen]](putty_screen.png)
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.
We will be demonstrating and practicing all these commands in class, but here's a quick reference of each command we will use:
| Command | Comment |
| mkdir dir | Makes a directory called dir. |
| pwd | Print Working Directory. |
| cd dir | Change to directory dir. |
| cd .. | Change to directory one directory above. |
| cd ../.. | Change to directory two directories above. |
| cd ~ | Change to your home directory. |
| cd | Change to your home directory. Equivalent to the previous entry. |
| ls | List files in the current directory. |
| ls -l | List files in the current directory (Long Format). |
| cp source dest | Copy file source to destination file dest. The original file is preserved. |
| mv source dest | Copy file source to destination file dest. The original file is not preserved. |
| rm file | Delete file. Once a file is deleted, there is no way to get it back. |
| rmdir dir | Delete directory dir. Once a directory is deleted, there is no way to get it back. |
| exit | End your session and exit the UNIX system. |
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:
| Command | Comment |
| ^G | Show/hide help. |
| ^K | Delete a line. |
| ^O | Save your work thus far. |
| ^X | Quit, 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.
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:
| Part | Comment |
| g++ | The GNU C++ Compiler. The actual program that converts our C++ code to something executable. |
| -Wall -W -s -pedantic-errors | The compiler flags. These flags tell the compiler how to behave. |
| file.cpp | The file you created that you want the compiler to compile. |
| -o executable | Tells 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!
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.