[CMake] Linking C program to external C++ library

Lucas.Pettey at engilitycorp.com Lucas.Pettey at engilitycorp.com
Thu May 28 13:59:22 EDT 2015


Thanks for the very complete answer, Brad.

I will implement your final suggestion since we have no control over the compiler scripts and already have some platform dependent variables set.

Lucas Pettey, PhD
HPCMP PETTT EQM CTA Lead
ERDC-DSRC OnSite
Vicksburg, MS
512-297-9833 Mobile (preferred)
601-634-2980 Office
lucas.pettey at engilitycorp.com

________________________________________
From: Brad King [brad.king at kitware.com]
Sent: Thursday, May 28, 2015 12:49 PM
To: Pettey, Lucas @ EngilityCorp
Cc: cmake at cmake.org; Dan Liew
Subject: Re: [CMake] Linking C program to external C++ library

On 05/28/2015 01:32 PM, Lucas.Pettey at engilitycorp.com wrote:
> It is interesting to note that the stdc++ library is in
> CMAKE_C_IMPLICIT_LINK_LIBRARIES and CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES
> but not in CMAKE_CXX_IMPLICIT_LINK_LIBRARIES.

A similar case was discussed here:

 http://www.cmake.org/Bug/view.php?id=14207#c33256

and deemed to be local misconfiguration of the compilers.
There is no reason a C or Fortran compiler should link to
the C++ runtime library.

> when the LINKER_LANGUAGE variable is not set, CMake
> links with the C compiler but does not add the stdc++ library.

That's because it sees stdc++ in the "C" implicit library list
so it knows the compiler front-end will add it.

> Is there any way to tell CMake not to add these other
> IMPLICIT_LINK_LIBRARIES when doing  a mixed language build?

Once could add

 set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "")
 set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
 set(CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "")

to the project after the respective languages are enabled
(by the project() or enable_language() commands).

-Brad



More information about the CMake mailing list