Set Up

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).

  1. Download and install CLion.
  2. 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.
  3. 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.

  1. Download and install CLion.
  2. 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.

  1. Download and install CLion. You may use snap if you like to.
  2. 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 #

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 bottom tail ./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 some cmake-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 any cmake-build-* directories. Using ls -a, verify that the directory contains main.c and the CLion settings in the hidden folder .idea.
  • Find your C compiler with cc --version. Use cat main.c, are the contents the same as in the editor? Compile main.c into a program main with
      cc main.c -o main
    
    Then execute the program: ./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.