Installing GDAL and CGAL on Windows with WSL

This guide explains how to install GDAL and CGAL on Windows using the Windows Subsystem for Linux (WSL), and how to connect it with CLion.

It should work for both Win10 and Win11.

Install WSL

WSL allows you to run a Linux environment on your Windows device.

Note: You must have Windows 10 or Windows 11 to be able to follow these steps.

To install WSL, open command prompt as administrator.

image

Run the following command:

wsl --install

This will start the process to install WSL on your device. Once the installation is complete, you will need to reboot your device.

After the reboot, wait a couple of seconds for the Ubuntu terminal to open and complete the installation. It will then ask you to specify a username and password.

image

Once you complete this step, your WSL is ready to use!

Note: You will not be able to use Ctrl + C/V for Copy/Paste on the Ubuntu terminal. Instead, go to Properties by right-clicking on the top of the terminal and enable Use Ctrl+Shift+C/V as Copy/Paste.

image

Install GDAL

To install GDAL, run the following commands one by one on your Ubuntu terminal:

sudo add-apt-repository ppa:ubuntugis/ppa && sudo apt-get update
sudo apt-get update
sudo apt-get install gdal-bin
sudo apt-get install libgdal-dev

If everything went correct, you’ve successfully installed GDAL!

Install CGAL

Let’s install CGAL now with the following two commands:

sudo apt-get update

image

sudo apt-get install libcgal-dev

image

If everything went correct, you now have CGAL as well!

Note: Before starting to use GDAL and CGAL on CLion, you will need to complete the following two steps.

Install CMake

To install CMake, run the following commands on your Ubuntu terminal.

Install the libraries that CMake depends on:

sudo apt-get install build-essential libssl-dev

Go to the tmp directory:

cd /tmp

Download the source code:

wget https://github.com/Kitware/CMake/releases/download/v3.20.0/cmake-3.20.0.tar.gz

When this is complete, extract the file:

tar -zxvf cmake-3.20.0.tar.gz

Go to the extracted folder:

cd cmake-3.20.0

Compile and install CMake:

./bootstrap

This may take some time, you should see the following when it is finished.

image

Now run the following command to make it:

make

This step will also take some time. Once it is finished, you can finally install it:

sudo make install

Finally, to check if the installation was successful, you can see the CMake version:

cmake --version

image

Install GDB

GDB is a debugger for C++ and you will need it in CLion to connect to WSL.

If you are installing GDB right after CMake, you are probably still in the cmake-3.20.0 folder on your Ubuntu terminal. First, go back to the home directory:

cd ../..

image

Install GDB with the following two commands:

sudo apt-get update
sudo apt-get install gdb

If this method does not work for you, you can also install it through the source code as explained in the second option on this page.

You can verify the installation by checking the GDB version:

gdb --version

image

Once you install GDB, you now have everything you need to connect to WSL in CLion!

Connect to CLion

Note: The steps to connect with WSL may change depending on your CLion version. This tutorial uses CLion 2021.3.

Go to Settings from File or by simply pressing Ctrl+Alt+S.

image

Under Build, Execution, Deployment, go to Toolchains. Then, add a new toolchain by clicking on the + sign and select WSL.

image

It should automatically detect all the fiels (Toolset, CMake, Debugger etc.). However, if you see an error for CMake that it cannot be found, click on Browse on the right-side of CMake and choose the correct file. You can find it under /usr/local/bin/cmake.

image

After this step, you may see the following warning under C++ compiler: Test cmake run finished with errors.
In this case, reboot your WSL by typing the following command on your Ubuntu terminal:

wsl.exe -t Ubuntu

This will close the terminal. Simply open it again by searching Ubuntu on your device. Now, if you check CLion again, you should not see the warning anymore.

Finally, do not forget to make WSL default by placing it on the top of the listed toolchains. You can do this by dragging WSL to the top, or by using the arrows.

image

Yay, you can now use GDAL and CGAL on Windows with CLion!