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

Brad King brad.king at kitware.com
Thu May 28 13:49:01 EDT 2015


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