# Export and implicit library dependencies

**URL:** https://discourse.cmake.org/t/export-and-implicit-library-dependencies/10716
**Category:** Usage
**Tags:** os:linux, tool:cmake
**Created:** [April 22, 2024, 4:28pm UTC](https://discourse.cmake.org/t/export-and-implicit-library-dependencies/10716 "2024-04-22T16:28:47Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Felix-El](https://discourse.cmake.org/user_avatar/discourse.cmake.org/felix-el/32/4524_2.png) [@Felix-El](https://discourse.cmake.org/u/Felix-El)
#### Post date: [April 22, 2024, 4:28pm UTC](https://discourse.cmake.org/t/export-and-implicit-library-dependencies/10716/1 "2024-04-22T16:28:47Z")

</div>

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](https://gitlab.kitware.com/cmake/cmake/-/issues/19523) and [#21225](https://gitlab.kitware.com/cmake/cmake/-/issues/21225) seem related but open.

What is recommended?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 27, 2024, 3:46pm UTC](https://discourse.cmake.org/t/export-and-implicit-library-dependencies/10716/2 "2024-04-27T15:46:31Z")

</div>

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?
