Clang-cl and Flang Fortran

Visual Studio incorporates the Clang-CL compiler, which is LLVM Clang with an MSVC-compatible command-line interface. This allows developers to use Clang as a drop-in replacement for the Microsoft Visual C++ compiler. The Visual Studio 18 2026 release brought along the Flang Fortran compiler, but it is currently mostly broken due to missing .mod modules. We demonstrate this issue here as other compilers could be similarly broken if incompletely or improperly installed, as might happen on HPC or cloud resources.

program test
use, intrinsic :: iso_fortran_env
end program

The MSYS2 flang works with that program, but the Visual Studio 2026 Flang does not, as it cannot find the “iso_fortran_env.mod” module.

Compilers like NVHPC and LLVMFlang have actual files like “iso_fortran_env.mod” installed with the compiler. Gfortran and Intel Fortran don’t have a physical file corresponding to these intrinsic Fortran modules. In part since Flang itself isn’t yet working in Visual Studio 2026, CMake isn’t able to recognize the Flang compiler with the ClangCL toolset.

cmake -B build -G "Visual Studio 18 2026" -T ClangCL -DCMAKE_Fortran_COMPILER=flang

results in errors about devenv and “unknown” Fortran compiler. Once Flang is fixed within Visual Studio, hopefully CMake will add support for the Flang compiler with the ClangCL toolset, as this would save users the effort of installing Intel oneAPI if they only want Visual Studio with Fortran.