[CMake] Fortran MinGW on Windows

Brad King brad.king at kitware.com
Fri May 31 13:04:25 EDT 2013


On 05/31/2013 05:47 AM, Leek, Jim wrote:
> Oh, if there any cmake way to get the fortran link flags
> I need to pass to g++? I know -lgfortran is all I need in
> this case, but if there was a generic way to get cmake to
> figure it out for me, that would be nice.

CMake is supposed to figure this out automatically.

Whenever CMake enables a language (project or enable_language)
such as C, CXX, or Fortran it detects the implicit link info
that the compiler front-end passes to the linker for executables.
It records this info in CMakeFiles/$v/CMake*Compiler.cmake
files.

Later when one uses add_library to create a Fortran library
and then add_executable to create a CXX executable that
links to the Fortran library, CMake knows that the link
step will need both C++ and Fortran implicit libraries.  It
uses the C++ compiler front-end to invoke the link step but
adds any implicit link information that it knows the Fortran
objects will need and that the C++ front-end does not add.
The -lgfortran flag is an example.

I just checked and this does work on MinGW, at least with the
MSYS Makefiles generator, g++, and gfortran.

* What version of CMake are you using?

* What generator are you using?

* What is in the CMakeFiles/*/CMake*Compiler.cmake files
  for values like CMAKE_C_IMPLICIT_LINK_LIBRARIES?

* Can you post a complete source example where it fails?

-Brad


More information about the CMake mailing list