On 3 September 2013 15:46, Brad King <brad.k...@kitware.com> wrote: >> I though that the recommended way to deal with it is: >> >> set_property(TARGET ${prog} PROPERTY LINKER_LANGUAGE CXX) > > This tells CMake that your "main" is provided by C++, but IIUC > it is still Fortran. You should still be able to link with the > Fortran front-end but need to get the C++ runtime library too. > > One way to do this is to tell CMake that the library uses C++ > using the IMPORTED_LINK_INTERFACE_LANGUAGES property on an > imported target: > > > http://www.cmake.org/cmake/help/v2.8.11/cmake.html#prop_tgt:IMPORTED_LINK_INTERFACE_LANGUAGES > > For example: > > add_library(externalCxxLib STATIC IMPORTED) > set_target_properties(externalCxxLib PROPERTIES > IMPORTED_LOCATION "/path/to/libexternalCxxLib.a" > IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" > ) > target_link_libraries(myFortranExe externalCxxLib) > > This should work if: > > - The project enables both Fortan and CXX languages > - The C++ compiler used is the same as that used to > build the static library > > Then CMake has enough information to add the C++ runtime > library to the link line when linking to the static library.
That's what I was looking for, but for me instead of adding C++ runtime, C++ compiler (icpc) is used for linking. So I have the same problem: undefined reference to `main' >From what I've read that's intentional(?), CXX has higher LINKER_PREFERENCE. I've tried changing the preference manually (only for ifort): set(CMAKE_Fortran_LINKER_PREFERENCE 100) but it has no effect. Any ideas? Marcin -- 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: http://www.cmake.org/mailman/listinfo/cmake