我正在尝试为Windows 10上安装的MinGW32 gfortran项目实施cmake。我目前需要对该软件使用32位MinGW。我运行了mingw-get update
和mingw-get upgrade
,这导致gcc和gfortran的版本为6.3.0。我从Windows 10 zip文件发行版安装了cmake 3.14.1,并将其添加到MinGW cmd环境的PATH中。当我在文件上运行cmake时,它无法通过其编译器测试,并且抱怨以下内容(下面包含完整的输出):
Unknown extension ".f" for file
在这种情况下,测试程序由cmake-3.14/Modules/CMakeTestFortranCompiler.cmake
生成。使用此小程序测试编译器应该很容易由带有默认规则的cmake和MinGW make程序处理。为什么不呢?
我正在从cmd窗口和名为1-run-cmake.bat的批处理文件运行以下文件,该文件具有以下内容。添加-DCMAKE_SH
选项是因为cmake抱怨路径中有sh.exe(由MinGW提供)。使用"MinGW Makefiles"
cmake生成器,因为它是32位MinGW环境。 cmake从build
文件夹运行。
set cmakeFlags=-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=gcc -DCMAKE_Fortran_COMPILER=gfortran -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_SH="CMAKE_SH-NOTFOUND" -G "MinGW Makefiles"
cmake %cmakeFlags% ..
错误输出为:
1-run-cmake.bat
-- The C compiler identification is GNU 6.3.0
-- The Fortran compiler identification is GNU 6.3.0
CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_FORTRAN_COMPILER_ENV_VAR
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.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 Fortran compiler: C:/MinGW/bin/gfortran.exe
CMake Error at C:/Users/sam/cdss-dev/StateMod/git-repos/cdss-app-statemod-fortran-utest/build-util/cmake-3.14.1-win64-x64/share/cmake-3.14/Modules/CMakeTestFortranCompiler.cmake:30 (try_compile):
Unknown extension ".f" for file
C:/Users/sam/cdss-dev/StateMod/git-repos/cdss-app-statemod-fortran-utest/test/build/CMakeFiles/CMakeTmp/testFortranCompiler.f
try_compile() works only for enabled languages. Currently these are:
C FORTRAN RC
See project() command to enable other languages.
Call Stack (most recent call first):
CMakeLists.txt:30 (project)
-- Check for working Fortran compiler: C:/MinGW/bin/gfortran.exe -- broken
CMake Error at C:/Users/sam/cdss-dev/StateMod/git-repos/cdss-app-statemod-fortran-utest/build-util/cmake-3.14.1-win64-x64/share/cmake-3.14/Modules/CMakeTestFortranCompiler.cmake:45 (message):
The Fortran compiler
"C:/MinGW/bin/gfortran.exe"
is not able to compile a simple test program.
It fails with the following output:
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:30 (project)
-- Configuring incomplete, errors occurred!
See also "C:/Users/sam/cdss-dev/StateMod/git-repos/cdss-app-statemod-fortran-utest/test/build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/sam/cdss-dev/StateMod/git-repos/cdss-app-statemod-fortran-utest/test/build/CMakeFiles/CMakeError.log".
顶级CMakeLists.txt文件为:
# Configuration information for cmake program
# - used when the 1-run-cmake.bat script is run
cmake_minimum_required(VERSION 3.0)
#--
# The following is apparently not recognized (must be uppercase) even though some docs show this
#SET (CMAKE_Fortran_COMPILER gfortran)
#--
# The following complain about gfortran not being found in the PATH, even though it is
#SET (CMAKE_FORTRAN_COMPILER gfortran)
#SET (CMAKE_FORTRAN_COMPILER gfortran.exe)
#--
# The following does not work - must be all UPPERCASE
#SET (CMAKE_Fortran_COMPILER "C:/MinGW/bin/gfortran.exe")
# --
# The following results in error: Unknown extension ".f" for file
#SET (CMAKE_FORTRAN_COMPILER_WORKS 1)
#--
# The following (mixed case) results in errors:
# Unknown extension ".F" for file
# Unknown extension ".f90" for file
#SET (CMAKE_Fortran_COMPILER_WORKS 1)
# --
# The following complains about not being able to compile a simple test program
# Not setting the compiler results in a cmake warning asking it to be set.
# Unknown extension ".f" for file
SET (CMAKE_FORTRAN_COMPILER "C:/MinGW/bin/gfortran.exe")
project(
statemod_unit
LANGUAGES C FORTRAN
)
enable_testing()
add_subdirectory(year)
由于编译器测试失败,我什至还没有编译我自己的源文件(目前是一个简单的例子)。匹配(或不匹配)情况的cmake约定很容易被破解。为什么即使cmd窗口中的PATH包含编译器,我也不能为其设置“ gfortran”(where gfortran
显示C:\MinGW\bin\gfortran.exe
)。
使用设置需要处理CMAKE_FORTRAN_COMPILER_ENV_VAR
时出现的错误,还是根本问题的征兆?
我陷入困境,无法找到前进的方向。