[CMake] [EXTERNAL] Re: linking mixed language executable; cmake choosing wrong compiler

Mitchell, John A jamitch at sandia.gov
Mon Jan 9 16:32:29 EST 2012


Thanks Brad.  Much appreciated.  

I can see that cmake has some relevant properties but I wasn't quite sure how to set them.  

I'll give this a shot.

________________________________________
From: Brad King [brad.king at kitware.com]
Sent: Monday, January 09, 2012 2:28 PM
To: Mitchell, John A
Cc: cmake at cmake.org
Subject: [EXTERNAL] Re: [CMake] linking mixed language executable; cmake choosing wrong compiler

On 1/9/2012 3:44 PM, Mitchell, John A wrote:
> add_executable(demo_cf_pointer demo_cf_pointer.F90)
> target_link_libraries(demo_cf_pointer I_Fortran -lstdc++)

CMake prefers to use the C++ compiler to link when any C++ is involved.
Some toolchains use a "prelinker" step that actually runs the C++ compiler
to handle template instantiations.  IIRC some vendors document that the
C++ compiler should be used if there is any C++ in the link.  This may
or may not still be true on modern tools, but that is the historical
reason for this behavior.

You can tell CMake explicitly to use the Fortran compiler to link:

   set_property(TARGET demo_cf_pointer PROPERTY LINKER_LANGUAGE Fortran)

CMake should still take care of the implicit libraries so you do not need
the explicit "-lstdc++" (though I have not tested this with MPI compiler
wrappers myself).

-Brad




More information about the CMake mailing list