Cmake with gfortran on Windows -- No CMAKE_Fortran_COMPILER could be found

1277 views
Skip to first unread message

Beliavsky

unread,
Aug 18, 2018, 8:03:19 AM8/18/18
to
I am new to using Cmake, which is a build tool often used in github projects.
I installed cmake version 3.12.1 on Windows 10 and tried to use it to compile the functional-fortran project and get a message "No CMAKE_Fortran_COMPILER could be found". The location of my installed gfortran is c:\equation\bin\gfortran.exe . What should I do?

c:\fortran\public_domain\github\functional-fortran\build>cmake ..
-- Building for: Visual Studio 15 2017
-- The C compiler identification is MSVC 19.14.26428.1
-- The CXX compiler identification is MSVC 19.14.26428.1
-- Check for working C compiler: C:/programs/Microsoft_Visual_Studio/2017/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x86/cl.exe
-- Check for working C compiler: C:/programs/Microsoft_Visual_Studio/2017/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x86/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/programs/Microsoft_Visual_Studio/2017/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x86/cl.exe
-- Check for working CXX compiler: C:/programs/Microsoft_Visual_Studio/2017/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x86/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The Fortran compiler identification is unknown
CMake Error at CMakeLists.txt:4 (enable_language):
No CMAKE_Fortran_COMPILER could be found.


Vishnu

unread,
Aug 18, 2018, 10:08:28 AM8/18/18
to
Can you post your CMakeLists.txt ? And are you sure you have a Fortran compiler?

Beliavsky

unread,
Aug 18, 2018, 1:21:08 PM8/18/18
to
On Saturday, August 18, 2018 at 10:08:28 AM UTC-4, Vishnu wrote:
> Can you post your CMakeLists.txt ? And are you sure you have a Fortran compiler?

I rebooted. Now the output of

c:\fortran\public_domain\github\functional-fortran\build>cmake ..

is

-- The Fortran compiler identification is unknown
CMake Error at CMakeLists.txt:4 (enable_language):
No CMAKE_Fortran_COMPILER could be found.

-- Configuring incomplete, errors occurred!
See also "C:/fortran/public_domain/github/functional-fortran/build/CMakeFiles/CMakeOutput.log".
See also "C:/fortran/public_domain/github/functional-fortran/build/CMakeFiles/CMakeError.log".

********************************************************

The output of printing a log file with c:\fortran\public_domain\github\functional-fortran\build>type "C:\fortran\public_domain\github\functional-fortran\build\CMakeFiles\CMakeError.log"

is

Compiling the Fortran compiler identification source file "CMakeFortranCompilerId.F" failed.
Compiler:
Build flags:
Id flags:

The output was:
1

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

The license for Visual Studio has expired.

The evaluation period for this product has ended.

Compiling the Fortran compiler identification source file "CMakeFortranCompilerId.F" failed.

I don't know why it is looking for Microsoft Visual Studio

*******************************************************

Here is the CmakeLists.txt file:

c:\fortran\public_domain\github\functional-fortran>type c:\fortran\public_domain\github\functional-fortran\CMakeLists.txt
# cmake version, project name, language
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(functional-fortran)
enable_language(Fortran)

# set output paths for modules, archives, and executables
set(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/include)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# if build type not specified, default to release
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "release")
endif()

# compiler flags for gfortran
if(CMAKE_Fortran_COMPILER_ID MATCHES GNU)
set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -C -fbacktrace")
set(CMAKE_Fortran_FLAGS_RELEASE "-O3")
endif()

# compiler flags for ifort
if(CMAKE_Fortran_COMPILER_ID MATCHES Intel)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -assume realloc_lhs -heap-arrays")
set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -C -traceback")
set(CMAKE_Fortran_FLAGS_RELEASE "-O3")
endif()

# compiler flags for Cray ftn
if(CMAKE_Fortran_COMPILER_ID MATCHES Cray)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -h noomp")
set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -g")
set(CMAKE_Fortran_FLAGS_RELEASE "-O3")
endif()

# library to archive (libfunctional.a)
add_library(functional src/lib/mod_functional.f90 src/lib/mod_interfaces.f90)
add_library(testing src/tests/mod_testing.f90)

# tests
enable_testing()
foreach(execid arange complement empty filter foldl foldr foldt head init insert intersection iterfold last limit map reverse set sort split subscript tail unfold union)
add_executable(test_${execid} src/tests/test_${execid}.f90)
target_link_libraries(test_${execid} functional testing)
add_test(test_${execid} bin/test_${execid})
endforeach()

install(DIRECTORY "${CMAKE_Fortran_MODULE_DIRECTORY}" DESTINATION "${CMAKE_INSTALL_PREFIX}")
install(DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" DESTINATION "${CMAKE_INSTALL_PREFIX}")

****************************************************************

I do have gfortran installed:

c:\fortran\public_domain\github\functional-fortran\build>gfortran --version
GNU Fortran (GCC) 9.0.0 20180715 (experimental)

Janus

unread,
Aug 20, 2018, 4:11:17 AM8/20/18
to
I think VS is the default generator on Windows. You can use a different generator (e.g. ninja) via "cmake .. -GNinja". Possibly you need to install ninja first. If you're in a MinGW console, you might also use the "Unix Makefiles" generator, I think (haven't done that in a while).

Cheers,
Janus

Arjen Markus

unread,
Aug 20, 2018, 5:49:17 AM8/20/18
to
For the PLplot project, which uses CMake extensively, I use -G "Unix Makefiles" for builds on Cygwin and -G "MSYS Makefiles" for builds under MinGW-w64/MSYS2.

Note: I have only limited experience with the Visual Studio generators - I prefer to use "NMake Makefiles" with plain Windows.

Regards,

Arjen

thecookie...@gmail.com

unread,
Jan 14, 2020, 12:36:18 AM1/14/20
to
**FIX FOR** "Cmake with gfortran on Windows -- No CMAKE_Fortran_COMPILER could be found" for anyone looking:

The error can happen when your CMAKE generator is Microsoft Visual Studio (default) which cannot use the Fortran Compiler without intel visual studio plugins. If you have intel cpu try this:

https://software.intel.com/en-us/articles/installing-microsoft-visual-studio-2017-for-use-with-intel-compilers

I have AMD CPU so I changed my CMAKE generator using -G "MinGW Makefiles" (there are different ones, make sure you have MinGw installed if you want to try this one) as a CMAKE argument. I also had to unspecify the target platform from x64 using DCMAKE_GENERATOR_PLATFORM="", but maybe you won't have to. Hope this helps someone.

Reply all
Reply to author
Forward
Message has been deleted
0 new messages