Set-up #
1. Install CLion #
For this course we will use JetBrains CLion. The software is licensed to students of Utrecht University (and other educational institutes) for free. You need to apply with your university e-mail address when the 30-day demo expires.
Note Feel free to use a different coding environment, but respect the hand-in requirements. Your code must compile with a recent GCC/LLVM compiler.
Windows users will use the GNU Compiler Collection (GCC) toolchain via the Windows Subsystem for Linux (WSL).
- Download and install CLion.
- Set up WSL/WSL 2 following the Microsoft installation guide. Choose Ubuntu if you are unsure what Linux OS to install. Installing the Windows Terminal is probably useful too.
- Configure the WSL toolchain following the CLion docs.
If your Windows version does not support WSL (after updating) you can use CygWin, a dual-boot set-up, or a virtual machine.
MacOS users may use LLVM via CLang.
- Download and install CLion.
- Follow the Required tools section to install the compilation tools.
It is of course also okay if you prefer a GCC installation, for instance via Homebrew.
For Linux users the most straightforward toolchain is GCC.
- Download and install CLion. You may use snap if you like to.
- Install GCC. For Ubuntu/Debian the GCC installation is:
sudo apt update
sudo apt install build-essential
It is of course also okay if you prefer a LLVM installation.
2. Using the shell #
WSL users make use of the Ubuntu shell, MacOS users can use the terminal.
Resources #
- A long but complete tutorial: https://swcarpentry.github.io/shell-novice/.
- Handy: cheat.sh.
Definitely need to know #
- Navigate (using
cd
,ls
,cwd
), and manipulate files (mv
,rm
,mkdir
,rmdir
). - Execute a program in the current directory, using
./program
; - Time the execution of a program using
time ./program
; - Grab the contents of a file
cat ./file
. Look at the top,head ./file
, or bottomtail ./file
; - Execute a program and append its output into a file:
./file >> output.txt
- Make your life easier by using TAB to complete filenames, and arrow up and CTRL+R to navigate and search in your command history.
3. CLion + shell compilation #
A C/C++ Integrated Development Environment (IDE) like CLion is greatly useful, but hides the underlying mechanics of compilation and execution. For this reason, it is recommended to start the first project with CLion as GUI, but using the shell to compile manually.
- Create a new C project with File -> New Project -> C Executable (C99) -> Create. A main.c will be created.
- In the project view in the left sidebar, you may see a
CMakeLists.txt
and somecmake-build-*
directories. We won’t be using CMake for now. Go to the settings, then Build, Execution, Deploy -> CMake. Delete all CMake profiles there, and save. - As an exercise, open a shell, and navigate to the project directory. Using the shell, remove
CMakeLists.txt
and anycmake-build-*
directories. Usingls -a
, verify that the directory containsmain.c
and the CLion settings in the hidden folder.idea
. - Find your C compiler with
cc --version
. Usecat main.c
, are the contents the same as in the editor? Compilemain.c
into a program main withThen execute the program:cc main.c -o main
./main
. “Hello, world!” should be printed to the terminal output. - Familiarize yourself with the environment. Introduce an error in the code, or make some modifications, and recompile. CLion is limited without CMake, it may not pick up errors in the source, but that is alright for now.