[CMake] Mixted C++/Fortran library on Windows [resolved]

Francis Giraldeau francis.giraldeau at gmail.com
Wed Feb 20 16:22:28 EST 2019


I just wanted to share a solution for mixing C++ and Fortran programs
on Windows using Visual Studio and Intel Fortran. The build was
failing at link time with undefined symbols comming from fortran code.
Actually, none of the fortran sources were compiled, even though it
was working fine on Linux using Makefiles.

When generating a shared library with both fortran and c++ sources like this:

    add_library(mix foo.f bar.cpp)

It produces the following .vcxproj (snippet):

  <ItemGroup>
    <ClCompile Include="C:\path\to\foo.f" />
    <None Include="C:\path\to\bar.cpp" />
  </ItemGroup>

The None compiler, well, does nothing.

The trick is to create two libraries, one for C++ code and the other
for the fortran code:

    add_library(foo foo.f)
    add_library(bar bar.cpp)

Then, both .vcxproj and .vfproj gets created and the fortran code is compiled.

It might be useful to document it somewhere. Perhaps it is already
documented and I haven't found it?

Cheers,

Francis


More information about the CMake mailing list