MSVC + mingw-w64 gfortran gives "gfortran.exe: error: /machine:x64: No such file or directory"
I am trying to use MSVC as the C and C++ compiler and (any) gfortran as the Fortran compiler.
The furthest that I got is by installing the m2w64-toolchain
Conda package, and:
call "c:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64
set FC=gfortran
set CXX=cl
set CC=cl
cmake -G "Ninja" .
Which gives:
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.5.7
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
-- The C compiler identification is MSVC 19.12.25835.0
-- The CXX compiler identification is MSVC 19.12.25835.0
-- The Fortran compiler identification is GNU 5.3.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.12.25827/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.12.25827/bin/Hostx64/x64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.12.25827/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.12.25827/bin/Hostx64/x64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working Fortran compiler: C:/Users/XXX/miniconda3/envs/m2w64/Library/mingw-w64/bin/gfortran.exe
-- Check for working Fortran compiler: C:/Users/XXX/miniconda3/envs/m2w64/Library/mingw-w64/bin/gfortran.exe -- broken
CMake Error at C:/Users/XXX/miniconda3/envs/m2w64/Library/share/cmake-3.9/Modules/CMakeTestFortranCompiler.cmake:44 (message):
The Fortran compiler
"C:/Users/XXX/miniconda3/envs/m2w64/Library/mingw-w64/bin/gfortran.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/XXX/GitLab-Runner/builds/1236142e/.../CMakeFiles/CMakeTmp
Run Build
Command:"C:/Users/XXX/miniconda3/envs/m2w64/Library/bin/ninja.exe"
"cmTC_40444"
[1/4] Building Fortran preprocessed
CMakeFiles/cmTC_40444.dir/testFortranCompiler.f-pp.f
[2/4] Generating Fortran dyndep file CMakeFiles/cmTC_40444.dir/Fortran.dd
[3/4] Building Fortran object
CMakeFiles/cmTC_40444.dir/testFortranCompiler.f.obj
[4/4] Linking Fortran executable cmTC_40444.exe
FAILED: cmTC_40444.exe
cmd.exe /C "cd . &&
C:\Users\XXX\miniconda3\envs\m2w64\Library\mingw-w64\bin\gfortran.exe
/machine:x64 CMakeFiles/cmTC_40444.dir/testFortranCompiler.f.obj -o
cmTC_40444.exe -Wl,--out-implib,libcmTC_40444.dll.a
-Wl,--major-image-version,0,--minor-image-version,0 && cd ."
gfortran.exe: error: /machine:x64: No such file or directory
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:5 (project)
-- Configuring incomplete, errors occurred!
The same happens with the NMake Makefiles
generator. Essentially, cmake passes /machine:x64
to gfotran which it doesn't understand. Why is cmake doing it? What am I doing wrong?