cmake thinks mingw-64 gfortran on Windows is broken

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

cmake thinks mingw-64 gfortran on Windows is broken

Ondřej Čertík-2
Hi,

I have previously reported the issue here:

https://gitlab.kitware.com/cmake/cmake/issues/17810

I was told to follow https://blog.kitware.com/fortran-for-cc-developers-made-easier-with-cmake/. I did in fact follow it. Just to be sure, I tried the `-DCMAKE_GNUtoMS=ON -DBUILD_SHARED_LIBS=ON` with no difference.

The problem is already at the "Check for working Fortran compiler" phase. As described in the issue above, CMake is trying to use gfortran for linking and passes incorrect options to it.

My understanding is that on Windows, one must use gfortran to build a dll, and then dynamically link it with MSVC, with the proper cmake options like `-DCMAKE_GNUtoMS=ON -DBUILD_SHARED_LIBS=ON`. However, this can only be done once the "Check for working Fortran compiler" phase passes.

How do I make CMake pass the "Check for working Fortran compiler" phase?

Thanks,
Ondrej
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: cmake thinks mingw-64 gfortran on Windows is broken

Brad King
On 03/09/2018 07:58 PM, Ondřej Čertík wrote:
> How do I make CMake pass the "Check for working Fortran compiler" phase?

The problem reported in issue 17810 is caused by trying to
enable C with MSVC and Fortran with GNU together at the same
time, e.g. `project(MyProj C Fortran)`.  These tools cannot
be used together directly.

The purpose of cmake_add_fortran_subdirectory as described
in the blog post is to avoid enabling Fortran in the main
project.  Instead Fortran is only enabled in a separate project
by itself, and the main project gets only C (and CXX).

If you want to use MSVC and Fortran together directly then you
need a Fortran compiler that works with the MSVC binutils.  The
Intel Fortran compiler for Windows, a commercial tool, is one
option.  There is also https://github.com/flang-compiler/flang,
which is currently maturing.

Alternatively you can use GNU from MinGW for all languages,
e.g. `CC=gcc CXX=g++ FC=gfortran cmake ../src`.

-Brad
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake