problem using gfortran with MSVC 18

I am trying to use cmake 4.3.0 to build a project with
-G “Visual Studio 18 2026”
and gfortran.

My CMakeLists.txt file includes:

set(CMake_ARCHIVE_OUTPUT_DIRECTORY ./my_fortran_lib)
set(CMake_RUNTIME_OUTPUT_DIRECTORY ./my_fortran_lib)
cmake_add_fortran_subdirectory(my_fortran_lib NO_EXTERNAL_INSTALL
PROJECT my_fortran_lib
ARCHIVE_DIR ${CMake_ARCHIVE_OUTPUT_DIRECTORY}
RUNTIME_DIR ${CMake_RUNTIME_OUTPUT_DIRECTORY}
LINK_LIBRARIES # link interface libraries
LINK_LIBS my_fortran_lib
LIBRARIES my_fortran_lib
)

When I run cmake I get the errors below:


– Selecting Windows SDK version 10.0.26100.0 to target Windows 10.0.26200.
– The Fortran compiler identification is unknown
– Detecting Fortran compiler ABI info
– Detecting Fortran compiler ABI info - failed
– Check for working Fortran compiler: C:/msys64/mingw64/bin/gfortran.exe
– Check for working Fortran compiler: C:/msys64/mingw64/bin/gfortran.exe - broken
CMake Error at C:/PROGRA~1/CMake/share/cmake-4.3/Modules/CMakeTestFortranCompiler.cmake:59 (message):
The Fortran compiler

"C:/msys64/mingw64/bin/gfortran.exe"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: 'D:/projects/fortran_cpp_cmake_test_visual_studio/CMakeFiles/CMakeScratch/TryCompile-58lv4u'

Run Build Command(s): "C:/Program Files/Microsoft Visual Studio/18/Community/Common7/IDE/devenv.com" D:/projects/fortran_cpp_cmake_test_visual_studio/CMakeFiles/CMakeScratch/TryCompile-58lv4u/CMAKE_TRY_COMPILE.slnx /build Debug /project cmTC_a296f

Microsoft Visual Studio Version 18.5.0.
Copyright (C) Microsoft Corp. All rights reserved.

The operation could not be completed. The parameter is incorrect.

Unfortunately, the directory TryCompile-58lv4u does not exist.