Skip to article frontmatterSkip to article content

Compiling and developing with graph-tool

Authors: Tiago P. Peixoto1, Max Falkenberg1, Martina Contisciani1,2
Affiliations: 1Inverse Complexity Lab, 2Central European University
License: CC-BY

This document describes how to setup a Docker container to compile and develop graph-tool, independent of the operating system — it should work on GNU/Linux, Windows, or MacOS.

The first step is to install Docker itself, which is not covered here. Just follow the instructions on the website.

Building an image

With docker installed, we proceed with building an image which contains a fully functional Arch GNU/Linux OS, which you can use to run and install programs, completely independently from your host OS.

The image specification is defined in a Dockerfile that you should download (also available in the repo), then build with the following command run the same directory where the file resides:

docker build --platform linux/amd64 -t gt-workbench --build-arg USER=${USER} --build-arg UID=${UID} .

Creating and running from a container

Before we can run anything with our image, we need to create a container, which is a persistent writable layer on top of the image — which is read-only after it’s created — that will allow us to have an interactive workspace. We create a container named gt-workbench[1] with the command:

docker create --platform linux/amd64 -p 3000-5000:3000-5000 -i -t -v .:/work --name gt-workbench gt-workbench

The container is in principle isolated from the host OS, but we usually want to exchange files with it; so the above command also binds the current working directory in the host OS with a directory /work inside the container.

Once created, containers will persist, also across reboots. But before we can do anything useful with a container we need to start it:

docker start gt-workbench

And finally, we may wish to start an interactive shell inside the container with

docker exec -w /work --user=$USER -it gt-workbench bash

which will put us inside the /work directory inside the container (which points to the current working directory in the host).

Compiling graph-tool inside the container

From inside the container we can clone the git repository

git clone https://git.skewed.de/count0/graph-tool.git

We now setup the configure script (this usually needs to be done only once):

cd graph-tool
./autogen.sh

and finally we can setup the compilation as follows

./configure --prefix=/usr CXX="ccache g++" MOD_CXXFLAGS="-flto" LDFLAGS="-flto"

We can now actually start the compilation by evoking make:

make -j 2

After compilation, we can install the library in the system with:

sudo make install

After that, we’re ready to use it:

$ ipython
Python 3.13.2 (main, Feb  5 2025, 08:05:21) [GCC 14.2.1 20250128]
Type 'copyright', 'credits' or 'license' for more information
IPython 9.0.2 -- An enhanced Interactive Python. Type '?' for help.
Tip: Put a ';' at the end of a line to suppress the printing of output.

In [1]: from graph_tool.all import *

And that’s it!

At this point, we can modify the source code and re-compile the library (which should go much faster, since only the differences need to be re-compiled).

Updating graph-tool version

To update the graph-tool version, we can run the following steps from inside the graph-tool folder:

git pull
make -j 2
sudo make install

And that’s it!

Footnotes
  1. The container name chosen is the same name as the image, but it does not have to be like this, as you can have many containers based on the same image.