UNB/ CS/ David Bremner/ teaching/ old/ cs2023/ lab guide

CS2023 Lab User's Guide

The purpose of this document is to familiarize you with editing, compiling, running, and documenting C programs in the Faculty of Computer Science Linux labs.

Facilities and Access

ITD415 has 40 Linux computers and is the primary Linux teaching lab. GWC112 has both Windows and Linux systems and can be used when ITD415 is unavailable or full. Note that these two labs are operated by Faculty of Computer Science (UNB-FCS), NOT by UNB's Integrated Technology Services (UNB-ITS). Although the computers in the FCS and ITS Windows labs use the same authentication server, and therefore the same passwords, this is NOT true for the FCS Linux labs.

Access to Faculty of Computer Science Labs is via the magnetic stripe on your student card. You will need to synchronize your FCS Linux password with your Novell PIN before you can start using the labs.

Login and Shell

In the following examples, "$" is a prompt from the shell, and is not to be typed!

You have two ways to login to one of the lab machines: In ITD415 (or GC112) simply login to one of the workstations From another location, use secure shell (ssh - use putty if you're logging in from a Windows machine):

In this course we'll focus on working from the command line, that is we'll use the bash shell directly via a terminal window. To open a terminal window, click on the terminal icon at the bottom of your screen.

Editing

Most of you are probably familiar with Emacs from CS 1073/1083. Emacs comes with a C mode as well. How do you get the C environment? Let's say you want to edit a C program called hello.c. In the terminal window type

$ emacs hello.c &

An emacs window will open up showing your hello.c program, with syntax-highlighting and other features for C programs.
You will be using Emacs primarily as a text editor, so you're welcome to use any other text editor, such as vi, pico, ...

You might be wondering what the & is doing in the command line example above. This will place in the background the process that is running Emacs, allowing you to keep using the same terminal window.

Compiling and Running

We will be using the gcc compiler. To compile (and link) hello.c and create an executable called hello, issue the following from the command line:

$ gcc -Wall -o hello hello.c

Note that on most Linux systems, cc is an alias for gcc.

To execute hello, type:

$ ./hello

The "./" is essential. You need to place it; in front of any of your own executable files. Why? It tells the shell where to look for hello (in this case, it's in your current directory, which is indicated by the "." shortcut). By default the shell does not look in your directories for the file; it only looks in certain system directories.

Documentation

You will be using Doxygen to document your programs (see the CS2023 Coding Standard). It's a widely used documentation system for C, C++, Java, and other languages. Have a look at the example C programs in the /fcs/courses/cs2023 directory. They are commented in Doxygen style. Doxygen is already installed on the FCS Linux machines. You can also install it on your own machine (if it's not there already). Doxygen has has many parameters, these are controlled by by a file Doxyfile in your project directory. Use the following minimal Doxyfile for this course.

PROJECT_NAME="CS2023 Assignment 1"
OPTIMIZE_OUTPUT_FOR_C           =YES
SOURCE_BROWSER          =YES
REFERENCED_BY_RELATION  =YES
REFERENCES_RELATION     =YES
GENERATE_LATEX          =NO
SEARCHENGINE            =NO

You should replace "CS2023 Assignment 1" with something appropriate for your current project.

Generating documentation is as simple as:

$ doxygen

Web pages documenting your code are stored in a directory called html, including your line-numbered and colour-coded source code.

Making a Tar archive

To bundle up a directory to hand in, you can use

tar zcvf dir.tgz dir

where dir is the directory name. To extract a (gzipped) tar file, you can use

tar zxvf dir.tgz

Making a typescript

To make a typescript (record of terminal session) use the script command. Type script filename to start recording your commands (and their output) in filename, and exit to stop.

Making a printout

To print a file, use the lpr command:

$ lpr hello.c

Debugging

We'll cover debugging with the Gnu debugger (gdb) in a separate tutorial.

Questions/Comments?

Don't be shy! Speak to, or email, your instructor!