


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



CS107 Handout 05 Spring 2008 April 4, 2008
This handout was written by Andy Gray, and updated by Justin Haugh and Jerry Cain.
This handout covers some of the basics of using the Leland UNIX environment to edit, compile, and submit your programs:
Logging in, class directory, starter files Editing your source files Compiling your program Submitting your program
If you find that you need more individualized help getting started, be sure to come to office hours next week. Office hours will be posted to the web site in the next few days or so, after the CS107 TAs have finalized their own schedules.
Getting Started
All of you will use the leland machines to submit your work. Most of you will probably do all of your development on the leland systems as well. The tools on the UNIX machines are excellent, but somewhat more difficult to get started with. Although we will be able to offer some support for those of you using your own PC or Macintosh, we suggest you use the UNIX tools whenever possible. Even though ANSI C/C++ is highly portable, we will be grading your submissions on the leland systems, so it is your responsibility to make sure that your program written on another platform works on the leland machines as well. In addition, working on the leland s makes your files available from any remote machine and backs up your work each night.
Once you've logged on, you'll find yourself in your home directory. Here's a quick overview of changing directories, creating directories, and copying files. If you're completely new to UNIX, it would probably be a good idea to stop by office hours so that one of us can show you around. The best UNIX reference for this class is CS Handout 6: UNIX Development, available on the website for those who didn’t pick up a hardcopy. I’m also a fan of the following Stanford site, which summarizes of good bit of UNIX relevant to CS107:
h t t p : / / u n i x d o c s. s t a n f o r d. e d u /
The "UNIX Command Summary" handout is particularly useful.
Please note that some of the resources referred to in the document require a Stanford Network Account and therefore may not be accessible.
You can create a new directory for all of your projects with the following (text that you type is bold):
myth5> mkdir cs
and then change to the directory with
myth5> cd cs myth5>
Notice that the prompt changes to reflect the directory you are currently working in. (The myth5 part indicates the name of the machine we're currently logged into, but there's nothing particularly special about this machine.)
The directory for class materials is /usr/class/cs107/. In here you'll find starter files that we provide for the assignments. You'll also find code samples. Let's copy one of the sample programs over to your brand new cs107 directory:
myth5> cd /usr/class/cs107/assignments myth5> ls assn-0-small-programs assn-0-small-programs-data assn-1-rsg assn-1-rsg-data myth5> cp -r assn-0-small-programs ~/cs
The last command copies all of the files in the sample directory recursively ( -r ) into your cs107 directory ( ~ is the same as your home directory, whatever it may be). Now, we've copied the sample directory over to your own cs107 directory.
Later when it's time to start working on the real assignments, you'll copy the starting files from /usr/class/cs107/assignments the same way.) You can get to your copy of the assn-0-small-programs directory this way:
myth5> cd myth5> cd cs107/assn-0-small-programs myth5> ls 01-ruth-aaron 02-word-games myth5> cd 01-ruth-aaron myth5> ls Makefile README ruth-aaron-numbers.c
Now that you've copied these files over, you can start editing the source code and compiling the program.
Editing Files
There are a number of editors you can use in the UNIX environment, but we'll just go through a brief overview of the most popular, emacs. Although it's incredibly powerful and really nice to use once you've figured it out, emacs can be a bit intimidating at first. If you go to Terman or Gates to work (or run an X server on your local machine), you
If all goes well, you'll get a few lines of intermediate output but no warnings or errors. If none of the source files have changed since the last compile, make will let you know (this often comes up when you forget to save your changes before recompiling).
Sometimes (for other classes), you may see gcc above instead of g++. gcc is the GNU C Compiler. It’s actually both a C and C++ compiler (C++ is a virtually a strict superset of C), but if you invoke it as g++ you have a better chance of getting it to recognize your C++ code as such (as opposed to C code) and linking against the right libraries. If you stick to using the Makefiles that we provide, then you won't need to worry about this issue. If you have questions about how to edit Makefiles, email us at the question queue and we’ll be happy to help you.
To clean up your workspace (delete .o object files, etc.) run make clean. The submission script described below will require you to do this before turning in your work.
Submitting
Before you submit your program you will need to write a README file that describes your submission. In it, you should describe how to run your program, and note any extra features and bugs (if any).
Once you've finished writing your program, there's just one more step you need to complete: electronic submission. To submit your assignment, change to your assignment directory. Then run the submit script:
myth5> /usr/class/cs107/bin/submit
The script presents a list of assignments and asks you to choose which one you are submitting. It then copies source files, the Makefile (if any), and README from the current directory to our submit directory. If after submitting you decide that you need to make some additional changes, you can run the submit program again and send us the new version of your code. We will look at the last submission we receive from you (and we'll determine the number of late days based on when you turned in the last submission). Submit instructions are also available at