Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
We build Flang on Intel x86-64 and OpenPOWER hardware running either Ubuntu or Red Hat.
Flang depends on forks of clang and llvm.
The clang fork, flang-compiler/flang-driver, has been modified to support compilation of Fortran files, Fortran-specific command-line options, and the flang toolchain.
The llvm fork, flang-compiler/llvm, has been extended to support enhanced debug metadata specific to Fortran. It also has bug fixes that have been exposed by flang but have not yet been fixed in the llvm repository.
The latest supported LLVM version is 6.0. Flang also supports LLVM version 5.0.
To use 5.0, substitute 50 for 60 in the build instructions.
Flang is built outside of the llvm source tree.
The Linux command-line examples below will install everything into the default system location unless you set a custom install location.
When building flang, your PATH must include the install bin directory.
Using a Custom Install Location
To specify a custom install location, in each step below
to every CMake command.
If you use
CMAKE_INSTALL_PREFIX in any step, you must use the same
CMAKE_INSTALL_PREFIX in every step.
When using a custom install location, you must make sure that the bin directory is on your PATH when building and running flang.
If you use
<INSTALL_PREFIX>/bin is not in your path,
you need to add several additional command-line arguments for CMake:
-DLLVM_CONFIG=<INSTALL_PREFIX>/bin/llvm-config -DCMAKE_CXX_COMPILER=<INSTALL_PREFIX>/bin/clang++ -DCMAKE_C_COMPILER=<INSTALL_PREFIX>/bin/clang -DCMAKE_Fortran_COMPILER=<INSTALL_PREFIX>/bin/flang)
Get Flang LLVM, build and install it according to instructions
cd where/you/want/to/build git clone https://github.com/flang-compiler/llvm.git cd llvm git checkout release_60 mkdir build && cd build cmake <your custom options> .. make sudo make install
Get the flang driver, build and install it
cd where/you/want/to/build git clone https://github.com/flang-compiler/flang-driver.git cd flang-driver git checkout release_60 mkdir build && cd build cmake <your custom options> .. make sudo make install
If you use
CMAKE_INSTALL_PREFIXin Step 1 and
<INSTALL_PREFIX>/binis not in your path, you need to add
-DLLVM_CONFIG=<INSTALL_PREFIX>/bin/llvm-configwhen invoking CMake, otherwise you will encounter an error related to
LLVMConfig.cmakenot being found.
Get the OpenMP runtime library, build and install it
cd where/you/want/to/build git clone https://github.com/llvm-mirror/openmp.git cd openmp/runtime git checkout release_60 mkdir build && cd build cmake <your custom options> ../.. make sudo make install
Get the flang source code
cd where/you/want/to/build git clone https://github.com/flang-compiler/flang.git
Build libpgmath and install it
Note that libpgmath on x86 requires a toolchain that understands AVX-512 instructions, such as gcc 7.2.
For example, you might add custom options similar to these:
The source for libpgmath is in flang/runtime/libpgmath.
cd where/you/want/to/build cd flang/runtime/libpgmath mkdir build && cd build cmake <your custom options> .. make sudo make install
Built flang and install it
cd where/you/want/to/build git clone https://github.com/flang-compiler/flang.git cd flang mkdir build && cd build cmake <your custom options> .. make sudo make install
(Alternative:) Build flang using Spack
Spack is a flexible package manager for HPC system and can be used to build flang and its dependencies.
git clone https://github.com/llnl/spack.git
Build Flang and its dependencies:
spack install flang
watch out for the installation path, the flang wrapper script in there is ready to use.
(optional) setup Flang as a compiler inside spack if you want to build spack package with flang:
spack compiler add path/to/flang/bin
Now you might want to edit your
flangwith any c compiler of your choice.
To test your installation, create a simple "hello world" program, like the following:
program hello print *, 'hello world' end
Next, compile the program in the following manner. We will assume the program is called hello.f90
% flang hello.f90
If the build succeeds, then you can execute the program in the following manner: