[CMake] linking main Fortran and C++
Michael Hertling
mhertling at online.de
Mon Oct 18 23:30:25 EDT 2010
On 10/19/2010 03:43 AM, Michael Scot Breitenfeld wrote:
> My main program is in Fortran and I have couple of
> files that are in C++. When I try to make the library,
> CMake uses CXX linking (archiving) to make the library.
>
> Which I guess is ok, but then when it links the main program it
> thinks that it is a CXX executable and uses the C++ compiler and
> not the Fortran compiler so compilation fails.
>
> How do I tell cmake to use fortran instead, I
> thought it would automatically do this from the .f90 suffix. I'm
> using cmake 2.8.1.
Set the LINKER_LANGUAGE property of your main program target
to "Fortran", and see the CMAKE_<LANG>_LINKER_PREFERENCE and
CMAKE_<LANG>_LINKER_PREFERENCE_PROPAGATES variables for more
information.
Regards,
Michael
> My test:
>
> PROJECT( Test )
>
> SET(PACKAGE_NAME "TEST")
>
> CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
>
> SET (CMAKE_Fortran_COMPILER gfortran)
> SET (CMAKE_CC_COMPILER gcc)
> SET (CMAKE_CXX_COMPILER g++)
>
> # libraries are all shared by default
> option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
>
> ENABLE_LANGUAGE(Fortran)
>
> SET(F_OBJ submain.f90)
>
> SET(C_OBJ test.cpp)
>
> ADD_LIBRARY (name STATIC ${F_OBJ} ${C_OBJ})
>
> ADD_EXECUTABLE(a.out main.f90)
>
> TARGET_LINK_LIBRARIES(a.out name)
More information about the CMake
mailing list