# static library with static library dependencies propagates its dependencies when exported as package

**URL:** https://discourse.cmake.org/t/static-library-with-static-library-dependencies-propagates-its-dependencies-when-exported-as-package/7468
**Category:** Code
**Tags:** os:linux
**Created:** [February 14, 2023, 7:28pm UTC](https://discourse.cmake.org/t/static-library-with-static-library-dependencies-propagates-its-dependencies-when-exported-as-package/7468 "2023-02-14T19:28:02Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ppavacic](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ppavacic/32/3167_2.png) [@ppavacic](https://discourse.cmake.org/u/ppavacic)
#### Post date: [February 14, 2023, 7:28pm UTC](https://discourse.cmake.org/t/static-library-with-static-library-dependencies-propagates-its-dependencies-when-exported-as-package/7468/1 "2023-02-14T19:28:02Z")

</div>

Hello,  
I have library which we will call libB with statically linked dependencies libE.a, libF.a and libG.a (prebuilt) in target\_link\_dependencies(libB PRIVATE libE.a libF.a libG.a PUBLIC m). I have defined different project progA which is using libB which is exported as B-config.cmake. B-config.cmake is imported by progA. progA doesn’t directly use libE, libF, libG, but when I try to build it I get linker error that libE.a libF.a libG.a are missing.  
This is was my logic: libE, libF, libG are PRIVATE and therefore they won’t be passed down when exporting B-targets.

I believe it could be solved by changing INTERFACE\_LINK\_LIBRARIES from generated file, but Im not sure how to do it.  
In target file I have line that looks something like this:

```auto
set_target_properties(libB PROPERTIES
  INTERFACE_LINK_LIBRARIES "libE.a libF.a libG.a m"
)

```

while I want it to look like this:

```auto
set_target_properties(libB PROPERTIES
  INTERFACE_LINK_LIBRARIES "m"
)

```

---

<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: [February 14, 2023, 9:25pm UTC](https://discourse.cmake.org/t/static-library-with-static-library-dependencies-propagates-its-dependencies-when-exported-as-package/7468/2 "2023-02-14T21:25:36Z")

</div>

This is required for static libraries because `libB` doesn’t actually contain the symbols it uses from `libE`, `libF`, or `libG`. Only a shared library, module library, or executable link will actually resolve this. Therefore these dependencies need to be forwarded through the export (they should be wrapped in `$<LINK_ONLY>` generator expressions. There is [an issue](https://gitlab.kitware.com/cmake/cmake/-/issues/22679) to have a new library type that does this “repack dependent objects into this library”, but it is still in the discussion phase.

---

<div class="post-metadata">

### Author: ![ppavacic](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ppavacic/32/3167_2.png) [@ppavacic](https://discourse.cmake.org/u/ppavacic)
#### Post date: [February 15, 2023, 12:01pm UTC](https://discourse.cmake.org/t/static-library-with-static-library-dependencies-propagates-its-dependencies-when-exported-as-package/7468/3 "2023-02-15T12:01:25Z")

</div>

Thank you for your reply.  
I guess only way to do this, the way I want it, in CMake is to repack all those libraries into one manually, which could be a bit of a hassle. Including all the dependencies of dependencies isnt that much of a work so I will do that.
