How to compile R/igraph from source, with all features enabled?

NOTICE: This thread is written for igraph developers. If you are a user trying to compile R/igraph on Windows or macOS: do you really need to do it? Consider using (possibly older) binary releases from CRAN instead.


In this thread, let’s write up detailed instructions on how to compile R/igraph from sources on all supported platforms: Windows, macOS (Intel/ARM), Linux.

This will be useful because it takes some time until CRAN generates all binaries. For 1.3.0, it took over a week and in the meantime, people keep asking about how to compile.

General notes

Make sure that all requirements are present:

  • C, C++ and Fortran compilers
  • GLPK and libxml2 libraries, including development headers
  • Ensure that R can find these

Then install.packages("igraph") will work.

Linux

Install the above requirements using the facilities of your Linux distribution.

Debian-based distros

sudo apt install build-essential gfortran libxml2-dev libglpk-dev

Windows

Install RTools. Be sure to follow the installation instructions precisely, including setting the PATH. The below instructions assume that you are using RTools 4.0 or later.

Open an RTools terminal and install the required dependencies using pacman. Instructions for using pacman are here.

First update the package index:

pacman -Sy

Install the requirements:

pacman -Sy mingw-w64-{i686,x86_64}-glpk mingw-w64-{i686,x86_64}-libxml2 mingw-w64-{i686,x86_64}-gmp

macOS

Choose a section depending on whether you want to use developer tools from the official RTools, MacPorts, or Homebrew.

RTools

TODO

Get the developer tools from:

Download the dependencies (GLPK and libxml2 libraries) from:

MacPorts

Warning: If you are using the official R distribution, using other compilers than what come with RTools is not officially supported by the R maintainers.

Install compilers and libraries:

sudo port install clang-14 gcc11 libxml2 glpk

We need to ensure that R will use the compilers and libraries from MacPorts. Place the following in ~/.R/Makevars:

CC = /opt/local/bin/clang-mp-14
CXX = /opt/local/bin/clang++-mp-14
FC = /opt/local/bin/gfortran-mp-11
F77 = /opt/local/bin/gfortran-mp-11
FLIBS = -L/opt/local/lib/gcc11 -lgfortran -lquadmath -lm
CPPFLAGS=-I/opt/local/include
LDFLAGS=-L/opt/local/lib

If you install different versions of compilers than what is shown above, the contents of Makevars will need to be updated accordingly.

Homebrew

Warning: If you are using the official R distribution, using other compilers than what come with RTools is not officially supported by the R maintainers.

TODO