Linker language not determined properly when building shared libraries
I have a C application with two dependencies, one of which is a
STATIC IMPORTED C++ library which in its turn depends on the standard C++ libs. If I build with
-D BUILD_SHARED_LIBS=OFF, everything works as expected, my application gets linked using the C++ linker such that the C++ system library is linked in.
-D BUILD_SHARED_LIBS=ON, CMake does somehow not detect the linker language correctly and uses the C linker instead, resulting in many linking errors.
I'm on macOS and use the "Unix Makefiles" generator under XCode 9 (clang++, clang are my compilers)
I attached a small, self-contained example cmake_linking_error.zip. To recreate the issue:
cmake -D BUILD_SHARED_LIBS=OFF .. && make. Towards the bottom:
Linking CXX executable run_app
cmake -D BUILD_SHARED_LIBS=ON .. && make. Now you should get
Linking C executable run_appand a lot of linker errors.
(you can also turn on
CMAKE_VERBOSE_MAKEFILE to see that in the first case
cc in the latter )