[CMake] Trying to mix C++ and Fortran code...

Caron, Michael C. (US SSA) michael.caron at baesystems.com
Tue Feb 23 10:16:03 EST 2010


I've just started using CMake and have great hopes for it making my life simpler.  I currently have a windows console project that mixes C++ and Fortran code.  I have the main body of the code (in Fortran), an interface to display code written in C++(in Fortran), and some display code (C++).  I have used Visual Studio .NET 2003 and Intel Fortran 9.0 to build and link these successfully already, by building the project files and tweaking the appropriate build settings.  I'd like to switch to cmake generated build files so I can cross compile on Linux with a minimal amount of effort.  I could build makefiles for the Linux side, but then I'd have the nightmare of keeping both builds in sync.

I have created the CMakeLists.txt files for each of the subprojects (Fortran executable, Fortran Lib, and C++ Lib).  I've also generated nmake makefiles for each of the subprojects and used them to build with expected results.  Both the Fortran and C++ libs are built successfully and the Fortran executable fails complaining about unresolved externals (makes sense since I didn't point it to the libs yet).  When I add the code to the Fortran executable CMakeLists.txt to add_subdir for each of the static libs, and add the code to link the static libs things start to fall apart.

When I generate the make files my C++ lib no longer builds.  Looking around online I discovered the FortranCInterface and the FortranCInterface_VERIFY(CXX) cmake command.  I added an include for the FortranCInterface and the FortranCInterface_VERIFY(CXX) to the executable CMakeLists.txt file figuring that might provide some insight.  When I try to run cmake on that CMakeLists.txt file cmake complains that it could not compile the simple test file for the verify.

I know I can mix C++ and Fortran using the compilers I have, I've done it.  I must be missing some cmake magic.  Hopefully it is something stupid and someone will be able to see it and point it out to me.

Thanks in advance,
Michael Caron

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100223/786ed4e9/attachment.htm>


More information about the CMake mailing list