CMSC 14300: Practice Set 1¶
In this course, we will have a number of practice sets, which are ungraded, but will assist you in getting additional practice with the course material and help you prepare for the graded assignments and quizzes.
The purpose of this practice set is to get you set up with the software tools you need in order to do your coursework in CMSC 14300. If you have your own computer that you expect to be using for the course (we are not assuming that you do, but many of you do), you can follow these instructions to set it up. If you are planning to work in the CSIL this quarter, or elsewhere not on your own computer, that is fine; the CS department's network provides all the software we will be using this quarter. In that case, you can skip straight to working through the latter parts of this document, setting up .vimrc and working through vimtutor.
Getting a terminal¶
Assuming you are setting up your computer, the very first thing to do is to make sure you have a UNIX-style terminal readily available on your machine.
- Mac - On Macintosh computers, there is a Terminal application already installed (in the Utilities folder under the Applications folder). Add Terminal to the Dock if it isn't already there.
- PC - On Windows computers, you will need to install WSL (the Windows Subsystem for Linux) if you haven't already. There are instructions for installing WSL at the following URL: https://learn.microsoft.com/en-us/windows/wsl/install. [^1]
- Linux - On Ubuntu Linux,
Ctrl-Alt-twill open a fresh terminal. If you're running some other kind of Linux, we'll assume you know what you're doing.
If your computer is a Mac, install Homebrew if you don't have it already. There is an installation command on the home page at https://brew.sh.
Checking for installed packages¶
Next, we will install several packages we will be using during the quarter. It is possible some of them are already present on your system, so, before installing each, you will want to check if it is already there.
You can type which to check whether or not you already have a program installed (and which -a if you want to see all the installations in your PATH directories, which are the various directories in which your system is configured to look for installed software).
For example, here is a check for an installation of python3 (the first one in your PATH; if you happen to have multiple installations, this would be the one that takes precedence based on the order in which software installation directories have been configured on your system):
Here is a check for all installations of python3:
$ which -a python3
/Library/Frameworks/Python.framework/Versions/3.8/bin/python3
/usr/local/bin/python3
/usr/bin/python3
(Incidentally, here is a command to see the current value of PATH, which lists the various directories configured to hold installed software:)
Here is a check for something I don't have installed, python99 (which doesn't exist):
When which has no response, it means one of the following: a) you don't have that software installed, b) you do have that software installed but it is not in your PATH (in other words, it is not installed into one of the locations where your system looks for software), or c) there is no such software.
Installing packages¶
From here on, to install a particular package, type either brew install <package> or sudo apt-get install <package> on Mac or non-Mac, respectively, where <package> is one of each item in the following list. [^2]
git, ifwhichdoes not show it already on your systemssh, ifwhichdoes not show it already on your systemmake, ifwhichdoes not show it already on your systemvim, ifwhichdoes not show it already on your systemclang, ifwhichdoes not show it already on your systemlldb, ifwhichdoes not show it already on your systemvalgrindon non-Mac systems, ifwhichdoes not show it already on your system [^3]criterion, installed withbrew install criterionfor Mac,sudo apt-get install libcriterion-devotherwise. [^4]tmux, ifwhichdoes not show it already on your systempython3, ifwhichdoes not show it already on your systemfiglet, ifwhichdoes not show it already on your systemgraphviz, ifwhich dotdoes not print a result [^5]imagemagick, ifwhich displaydoes not print a result [^6]
In general, it should not be especially critical exactly which version you have of each of these packages, as long as it's recent. If you encounter any difficulties because of an out-of-date version of an application at any point in the future, you will be able to address it easily with a package manager. We might also ask you to install more software than these items as the course progresses.
Mac-only: streamlining the Criterion library¶
If you are on a Mac, and only if on a Mac, then please do the following steps to streamline the use of the Criterion library throughout the quarter. If you are on a different platform, skip ahead to "Once all of the software....".
In a terminal window, run:
It is likely that the output is /opt/homebrew and, if so, the commands below can be run as-is on your system. If you get a different output, then substitute that output for /opt/homebrew in each place where it occurs in the below commands - but, be sure to keep the /lib and /include that occur after it.
Run:
If the result is /bin/bash, then run the following. If not, skip ahead to "If the result is....".
Do not copy-and-paste the below, but rather manually type it into your terminal. The apostrophes here need to be straight quotes and not curly quotes, and because of the typesetting, if you copy from this document, you will get the wrong ones.
echo 'export LIBRARY_PATH="$LIBRARY_PATH:/opt/homebrew/lib"' >> ~/.bash_profile
echo 'export CPATH="$CPATH:/opt/homebrew/include"' >> ~/.bash_profile
source ~/.bash_profile
If the result is /bin/zsh, then run the following. Do not copy-and-paste the below, but rather manually type it into your terminal. The apostrophes here need to be straight quotes and not curly quotes, and because of the typesetting, if you copy from this document, you will get the wrong ones.
echo 'export LIBRARY_PATH="$LIBRARY_PATH:/opt/homebrew/lib"' >> ~/.zshrc
echo 'export CPATH="$CPATH:/opt/homebrew/include"' >> ~/.zshrc
source ~/.zshrc
Setting up .vimrc¶
Once all of the software above has been installed (excepting valgrind on Macs), please create the following file to manage the settings in your installation of vim. [^7] The file must be named .vimrc (note the file name starts with a dot) and it needs to reside in your home directory. Please note that files whose names begin with a dot are hidden, so you may not be able to see the file once it has been created. Once you know vim a bit better, you will be free to make whatever changes to .vimrc you like, but, for now, please copy the following text verbatim into that file:
filetype on
syntax on
set number
set shiftwidth=2
set tabstop=2
set expandtab
set nowrap
set autoindent
set cindent
autocmd FileType make set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab
set colorcolumn=80
As long as a file with exactly this name resides in your home directory, vim will refer to it for configuration. The effect of these settings will be to make your vim environment customized for C programming, with proper syntax coloring and indentation. (The next-to-last line is for special handling of Makefiles, which have very specific indentation requirements.) The last line turns on a guide to help you identify lines longer than 80 characters.
Finally, run vimtutor at the command line and please work through the entire tutorial at some point before you begin the first assignment.
[^1]: If you encounter great difficulty getting WSL to work, an approach that has helped address problems in the past has been to:
1. Check existing Linux installations with wsl --list.
2. Unregister all such installations (for example, Ubuntu) with wsl --unregister <linux-distro>.
3. Uninstall Linux distros and WSL itself under Windows Apps.
4. Install WSL from scratch.
Note that this will result in the loss of data stored in previous WSL installations.
[^2]: If you are using Linux or WSL and trying to install clang (or another application) and apt-get doesn't seem to know this package exists, run sudo apt-get update (and, after it finishes, try again).
[^3]: Valgrind is not available on Macs, unfortunately. Mac users can ssh into linux.cs or sit in a Linux CSIL room to use valgrind in the few cases this quarter where it's required.
[^4]: There is no criterion application; it is a C library. As a result, there is no which check to see if it is there; you'll find out when we start using it, if it's properly installed. (Criterion is a unit-testing package, something like pytest for C.)
[^5]: This package is a collection of software, with dot being one of the things you can check the existence of to confirm installation of the entire package.
[^6]: This package also installs programs with different names than the name of the package itself, and thus must also be tested indirectly.
[^7]: vim is a text editor that we will be using for C files this quarter.