Contents
Changelog:
- 17 August 2020: restructure this to be about getting a suitable Unix-like environment, not just about getting a C compiler, as the requirements for assignments has changed over time
- 25 August 2020: be explicit that the “Linux Lite” instructions assume a graphical login and add a section on what parts apply with SSH; change references from “lab machines” to “department machines”
- 29 August 2020: corect Unix tutorial link
This lab is optional. TAs will likely not be available during lab time yet, you’ll need to do it on your own. If you run into problems, use Piazza to get help.
For this class, we would suggest that you have access to a Unix-like environment where you can compile C code.
Assignments in this class will often use C. C is very close to machine language without the headaches associated with assembly. We will distribute some tools written in C that we expect to compile and run relatively early in the semester, and later in the semester, we will have some assignments that require modifying C code.
In addition to using C, we generally assume a Unix-like environment for compiling and running the C code. Several assignments will be distributed with Makefiles, which require the Unix utility make
and Unix-like command line to be available. In addition, for one assignment, we distribute an autograder tool which uses Python 3.
We have been developed and tested our assignments on a Linux-like environment similar to the lab machines. They may work in other environments, and in the past students have in fact had success, for example, using OS X or the Windows Subsystem for Linux for almost all assignments.
However, we do not have the staffpower to support arbitrary student systems. If the suggestions below fail for any reason, our official answer is you may program on the lab machines instead.
It is on you to arrange access to those machines in order to complete your assignments. Excuses such as my computer crashed
or I had trouble installing the compiler
will not be accepted.
That said, we will sometimes provide suggestions for how a lab or homework could be done from your home machine. If those work for you, great. If they do not, you may program on the lab machines instead.
If you have your own tip, post it on piazza so everyone can benefit.
Suggested Techniques
Not all paths to C and a Unix-like environment are created equal, but there are a lot of paths. This is my general priority order.
-
Program remotely on the department Unix machines. For how to do this from home, see how to use remote desktop,
ssh
andscp
. These machines come with a version ofgcc
by default, but you can access a more recent C compiler by runningmodule load gcc
(forgcc
) ormodule load clang
(forclang
). (See also this guide to modules on the department machines.)Warning: Do not submit files by copy-paste from
ssh
terminals without looking at them first! Copy-paste can introduce line breaks, backslashes, and so on where they do not belong. -
Go native. Install a good Linux distro, or make do with C and a Unix-like environment on other OSs
-
Use virtualization, such as virtualbox. Note, you’ll need a 64-bit image of Linux, like the one 2150 has used recently. Virtualization occasionally messes up timing, so it might not be good for the last part of the course, but it should hold you over until then.
-
Use an online IDE; Cloud9 and Koding are known to work for all parts of this course (but may be a bit slow for the performance assignments); codio, ideone, and ShiftEdit might as well. One bit of setup, though: once you log in and open a project in one of these online IDEs, get a terminal and type
sudo apt-get update sudo apt-get install xdg-utils libc6-dev-i386 gcc-multilib make
C command line
C files can be compiled on any Linux system using gcc -x c filename.c
, clang -x c filename.c
, or llvm-gcc -x c filename.c
. Most systems will have only one of these three installed; it does not matter which one you use.
If you have no main
method or otherwise want to produce an object file instead of a final executable, add -c
to the command line.
Recent compilers on the department machines
On the department machines, the default gcc
is pretty old, but you can get access to more recent one by running module load gcc
. Similarly, a recent verison of clang
is available with module load clang
.
Linux Lite
We assume you’ll use Linux for the labs in this course.
Upon logging into Linux, assuming you’re logging in via graphical interface (such as through NX), you’ll want access to
- A terminal window
- An editor of some kind
- A web browser
I suggest getting the terminal first by pressing Alt-F2 and typing gnome-terminal
, konsole
, or xterm
(they may not all work, but at least one should).
You can then get an editor by typing into the terminal one of geany &
, gedit &
, kate &
, nano
, pico
, emacs
, or vim
(or others, if you know others); and you can get a browser with firefox &
or chromium-browser &
. The &
means “Run this in the background and let me type other stuff in the terminal while it is running”.
Other important commands you can use in the terminal:
pwd
tells you where you are currently in the file systemls
tells you what files are in the current foldermkdir
makes a new directorycd ..
go one spot higher in the directory tree (if you are in/home/mst3k/funbox/whee/
thencd ..
will move you to/home/mst3k/funbox/
)cd dirname
to enter directory dirname (if you are in/home/mst3k/funbox/
thencd whee
will move you to/home/mst3k/funbox/whee/
)- The Tab key will autocomplete what you are typing; pressing it twice will list all possible autocompletions. For example, instead of typing
/home/mst3k/funbox/whee/
I can probably type/h
Tabm
Tabfu
Tabwh
Tab. This not only saves typing, it reduces the chances of typos.
You might also be interested in this Unix tutorial (from our local research computing center).
Linux Lite with SSH
If you login into Linux via SSH instead of via a graphical interface, you won’t have to do any work to get a terminal, but that’s all you’ll have.
You won’t be able to (usefully) run a web browser on the remote machine; instead, you’ll probably using a web browser on your local (non-Linux) machine and transferring files using our instructions on SCP.
However, you’ll still be able to take advantage of the above advice regarding using the terminal and finding text editors (though you won’t be able to use any of the text editors you’d run in the background).
Testing your compiler
If you think you have a compiler properly installed,
- create
hello.c
from Figure 1.1 on page 2 of the textbook (or here) - compile it as described in §1.2, and
- run it as described in §1.4