Building the LLVM Flang Fortran compiler

1 minute read

Nvidia has supported Flang since 2015, a Fortran compiler frontend to LLVM. Flang is supported by Cmake ≥ 3.10. 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.

  1. install Clang apt install clang
  2. download Flang binary and extract to ~/.local/flang
  3. add to ~/.bashrc
    export PATH=$PATH:$HOME/.local/flang/bin
  4. open a new Terminal and check
    flang --version

Building Flang

For casual use, it’s far to download 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.




Leave a comment