Computer Labs
Four compulsory computer labs during week 3, 4, 5, 6 of study period 3. You are expected to solve (most of) the lab assignments before the lab session (contact a teacher if you need help).
The schedule for the labs is in the course plan.
Sign up for the labs at sam.cs.lth.se/Labs, groups of two students.
The labs will be published during the first week.
Sign-up for the labs will open after the course has started.
- Assignments: Laboratory Exercises, C++ Programming.
Files for the labs (see the lab assignments for download instructions):
Lab | About | Files | Notes |
---|---|---|---|
1 | Basic C++ Programming | lab1.tar.gz | [1,3] |
2 | Introduction to the Standard Library | lab2.tar.gz | [2] |
3 | Strings and Streams | lab3.tar.gz | |
4 | Standard Containers and Algorithms | lab4.tar.gz | [4] |
Notes, corrections and additions
[1] 30/1: If you do the labs on a Mac with the standard XCode development tools, you need to be aware that Apple uses llvm, so the commands gcc
and g++
are aliases for clang
and clang++
. This is not obvious, as clang and gcc are command-line compatible, so what is written about g++
also applies to clang++
. See below for more info
[2] 30/1: The file words
can be found in /usr/share/dict/words
on the lab computers (and most Linuxes). If it is missing on your computer you can either copy it from there, or download it here.
[3] 31/1: The Makefiles in buggy_programs
did not work on the school computers, as they had clang++
as the compiler and the flag -Og
which did not work on the clang version installed. Changing the compiler to g++
or the flag to -O0
does work.
A new version or the tar archive with updated makefiles is uploaded.
[4] 26/2: An alternative benchmark program, using the library google benchmark. It is more or less a drop-in repacemen for nstime.cc, with the same assumptions about file and class names.
The main program is in nsbench.cc, and it should be built with cmake, using this CMakeLists.txt.
create a build directory and build it, with the typical
mkdir build & cd build cmake .. make nsbench
It will download and build the dependent library, google benchmark.
(google benchmark can also use the testing framework google test but that is disabled in the CMakeLists.txt file with the option -DBENCHMARK_ENABLE_TESTING:BOOL=OFF
due to build problems). This code and CMakeLists.txt has been tested on the school Linux machines, on a Debian box and on MacOS with the compiler from XCode.)
About the lab environment
Please note that the labs are done in a Linux command line environment. The labs can also be done on Mac OS or under the Windows subsystem for linux (WSL). You will not use an integrated development environment, but run the compiler, debugger, etc. directly from the command line.
The first lab introduces the tools. If you are not familiar with working at the command line you are recommended to start early with the first lab.
A brief introduction to working at the command line (in swedish) can be found on the EDAF30 web page. (Please note that the parts of the page related to mounting your home directory are specific to the Windows computers at Campus Helsingborg and do not apply when working on your own machine.)
If you find the command line difficult or confusing, please ask. It may be unfamiliar, but it should not be a big obstacle to completing the course.
Doing the labs under Windows
The lab instructions are written for a Linux system, but they can be run on Windows 10 under the Windows subsystem for linux (WSL). The web page for EDAF30 contains instructions for setting up a suitable environment under Windows 10 (in swedish). The instructions assume that WSL is activated.
Doing the labs under MacOS
The labs can be done on a Mac if you have XCode (or the XCode command line tools) installed.
There are two things to be aware of. Firstly, the debugger shipped with XCode is lldb
(and not gdb
). See the footnote in lab1.
For an introduction to lldb
, see https://lldb.llvm.org/tutorial.html.
Apple has a table of equivalent gdb/llvm commands.
It is possible to install gdb on a mac, for instance with MacPorts or HomeBrew, but note that the program needs to be signed, which may be a bit tricky the first time.
Secondly, valgrind
does work on MacOS, but is usually not available for the latest version of the operating system, as porting it takes some time.
Also note that (unless you install the GNU compilers yourself), gcc
and g++
are aliases to clang
and clang++
. The two compilers are command line compatible, though, so you shouldn't have any problems with that.