Assignment 0

Basic setup and knowledge for the course

This is a preparation assigment. It is unmarked and has no deadline, but it will help you for the following assignments.

The course assignments will be based on C++. If you need a refresher, this is a good series of tutorials. The same website is also a very good reference for the C++ standard library data structures, functions and algorithms. For example, if you want to know the member functions of a list or a map.

Please use the following instructions to have working system to compile C++ files with CGAL and other external libraries. It will be useful to hit the ground running in week 2.

How to install C++ libraries?

The simplest way to install libraries like CGAL or GDAL depends on your operating system. See the sections below.

Windows

The simplest way under Windows is… to install Linux!?

Installing all the libraries listed above is possible directly under Windows, but it is often a massive pain, so we recommend you use WSL—Windows Subsystem for Linux, which installs a Linux environment “inside” Windows (Win10 or Win11).

It works, and you can even use CLion (the Windows version) and use the compiler/libraries/debugger from WSL.

Just follow this tutorial, which also covers the installation of CMake and GDB.

If you don’t want to use WSL and instead prefer to use Visual Studio’s native C++ compilers and debuggers, have a look at this tutorial instead.

Mac

The easiest way is to use Homebrew (recommended), although it’s quite easy to use an alternative like MacPorts or to install them manually (follow the Linux or Unix instructions if there are none for Mac).

An example to install CGAL with Homebrew:

brew install cgal

The paths used by Homebrew are: /usr/local/include (for headers) and /usr/local/lib (for libraries).

Linux

Use the package manager of your distribution (eg apt in Ubuntu/Debian) or install them manually.

An example to install CGAL with apt:

sudo apt-get install libcgal-dev

How to use C++ libraries?

Anything in the standard library works after including a header. For example, if you want to use std::cout and its << operator, you need include iostream:

#include <iostream> 

If you need to use an external library (eg CGAL), you will first need to add the required paths during compilation and linking. In IDEs (like Visual Studio or Xcode), this is done in the GUI. If you use CMake, this is typically done in your CMakeLists file by first calling a script that finds the library. An example using CGAL:

find_package( CGAL REQUIRED )

The REQUIRED keyword makes CMake generate an error if CGAL is not found. This command sets a number of variables with the required paths. Then, you should set the include path, which for CGAL is done as:

include( ${CGAL_USE_FILE} )

This is a bit non-standard, since for most libraries the include_directories command is used instead. For example, with GDAL it is:

include_directories( ${GDAL_INCLUDE_DIR} )

Since CGAL is a header-only library, nothing else is necessary. But for libraries that have library files, linking to them is also necessary. An example with GDAL:

target_link_libraries(your_program_name ${GDAL_LIBRARY} )

Only after those steps, adding the required headers in your .cpp file will work:

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>

Libraries and dependencies

Note that libraries can themselves have other libraries as dependencies. For instance, CGAL requires Boost, GMP and MPFR. If you use a package manager, like Homebrew or apt, these should be installed automatically with CGAL. If not, you will need to install them manually.

Also note that these libraries’ paths might also need to be set up in your CMakeLists.

Testing your installation

If you want to test your setup, how about you use one of the CGAL library examples (eg this one with polygons). This will be extra useful since CGAL will be used for homework assignment 1.

Likely useful software for the course