Export and implicit library dependencies

On Linux, I’m building a shared library with CMake and exporting a find config for other projects to find_package it. Now the C++ linker adds dependencies on implicit libraries (libcplusplus and more).

If I try to import this shared library into a C-only CMake project for consumption by an executable, the linker complains about libcplusplus etc missing.

I have tried to set LINKER_LANGUAGE CXX on the import target but this had no effect (not supported on import targets due to false == cmTarget::CanCompileSources()).

Adding CMAKE_CXX_IMPLICIT_LINK_LIBRARIES to the LINK_INTERFACE_LIBRARIES property of the import target did work.

I could probably do the same on the export side to free users from this but I’m not sure it is the right approach anyway. Issues #19523 and #21225 seem related but open.

What is recommended?

Is the shared library built with -stdlib=libc++? Even if the C++ compiler is used to link, that flag probably needs passed through. Does it help if you add that flag as a compile option to the exported target?