Building the LLVM Flang Fortran compiler

Since 2015, Nvidia has supported Flang: a Fortran compiler frontend to LLVM. Flang is supported by Cmake ≥ 3.10, although CMake ≥ 3.14 is recommended in general to support more Fortran 2008 features. Meson ≥ 0.50 supports Flang as well. Flang is increasing support for Fortran 2008, including submodule.

Flang f18 is a new LLVM Fortran compiler front-end based in C++17 instead of the monolithic C code inherited from PGI that become the first-generation Flang.

Flang is invoked in CMake ≥ 3.10 by

FC=flang CC=clang CXX=clang++ cmake ..

How to install Flang

Pick ONE of the following:

  • Download the latest Flang Linux binary release
  • Compile from source (not recommended for casual Flang users)

Download Flang binary

Flang prerelease binaries are provided for Linux. OSX, Windows, BSD support is in work.

Download Flang binary and extract to ~/.local/flang

Add to ~/.bashrc

export PATH=$PATH:$HOME/.local/flang/bin
export LD_LIBRARY_PATH=$HOME/.local/flang/lib/:$LD_LIBRARY_PATH

Open a new Terminal and check

flang --version

Building Flang

For casual use, consider starting instead by downloading the Flang binary as above.

Building the LLVM Flang Fortran compiler from source is a resource-intensive process.

  • You need a moderately powerful PC to compile Flang with > 100 GB of free space on the drive you build Flang on. Flang install is small, but Flang build process requires a lot of drive space.
  • Don’t use too much RAM with the -j option of make for building Flang. It maxed out RAM on a PC with 32 GB of RAM with make -j. Try just plain make.
  • follow the Flang build instructions sequentially. Don’t try to build later parts while earlier parts are still building, this will not work properly.