The CMAKE_*_COMPILER variables are set correctly. The CMAKE_*_IMPLICIT_LINK_LIBRARIES have a whole bunch of libraries probably generated from the Cray wrapper.
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. Also, when the LINKER_LANGUAGE variable is not set, CMake links with the C compiler but does not add the stdc++ library. On the Cray systems, the wrappers correctly invoke all necessary libraries, thus CMake is working harder than it needs to. Is there any way to tell CMake not to add these other IMPLICIT_LINK_LIBRARIES when doing a mixed language build? Thanks, Lucas Pettey, PhD HPCMP PETTT EQM CTA Lead ERDC-DSRC OnSite Vicksburg, MS 512-297-9833 Mobile (preferred) 601-634-2980 Office lucas.pet...@engilitycorp.com ________________________________________ From: Brad King [brad.k...@kitware.com] Sent: Wednesday, May 27, 2015 12:36 PM To: Pettey, Lucas @ EngilityCorp Cc: cmake@cmake.org; Dan Liew Subject: Re: [CMake] Linking C program to external C++ library On 05/21/2015 06:00 PM, lucas.pet...@engilitycorp.com wrote: > I am trying to compile a code written in C, but using an external > library that contains C++ functions. I am on a Cray system and > everything works if I manually link with the cray CC wrapper. > When I change the linker language with this command: > > set_property(TARGET adh PROPERTY LINKER_LANGUAGE CXX) > > CMake is using the CC wrapper, but adding -lstdc++ to the link line. > This causes an error. Can anyone tell me how to not get this added library? CMake detects the libraries implicitly added by the compiler front-end for each language. When mixing languages it chooses to link using the compiler front-end for one of the languages and adds the implicit libraries needed for other languages and not added by the chosen one. This case looks strange because you are telling it to link with the C++ compiler but CMake is still adding the implicit library for C++. Look at CMakeFiles/${CMAKE_VERSION}/CMake*Compiler.cmake for details of the compiler detected for each language. Look for these variables: CMAKE_C_COMPILER CMAKE_C_IMPLICIT_LINK_LIBRARIES CMAKE_CXX_COMPILER CMAKE_CXX_IMPLICIT_LINK_LIBRARIES To what are they set? Thanks, -Brad -- 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://public.kitware.com/mailman/listinfo/cmake