# WHOLE\_ARCHIVE with transitive Dependencies

**URL:** https://discourse.cmake.org/t/whole-archive-with-transitive-dependencies/9344
**Category:** Usage
**Created:** [November 2, 2023, 4:45pm UTC](https://discourse.cmake.org/t/whole-archive-with-transitive-dependencies/9344 "2023-11-02T16:45:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![kolrami](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kolrami/32/3970_2.png) [@kolrami](https://discourse.cmake.org/u/kolrami)
#### Post date: [November 2, 2023, 4:45pm UTC](https://discourse.cmake.org/t/whole-archive-with-transitive-dependencies/9344/1 "2023-11-02T16:45:34Z")

</div>

After reading the discussion in [https://gitlab.kitware.com/cmake/cmake/-/issues/24504](https://gitlab.kitware.com/cmake/cmake/-/issues/24504) I decided to post some follow up question here.

The mentioned discussion talks about cyclic dependencies but I actually have an issue with normal transitive dependencies. Let’s say we have static libraries A, U and an executable T.

A which “links” against U  
T which links against U A

A of course only “links” by using target\_link\_libraries to get the include paths from U.

When I now specify to link against U with the WHOLE\_ARCHIVE option (using the override in my case) the final linker command will link against U twice, both times with the whole-archive option. This results in a multiple definition error.

Is there a solution to this?

P.S. The background of using WHOLE\_ARCHIVE at all is that T is a test executable for testing the library U. To generate coverage data (uncovered) also for unused object files I want to include the full library.

---

<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: [November 2, 2023, 9:24pm UTC](https://discourse.cmake.org/t/whole-archive-with-transitive-dependencies/9344/2 "2023-11-02T21:24:47Z")

</div>

@marc.chevrier @brad.king Maybe we want to dedupe libraries like Xcode 15 wants for `WHOLE_ARCHIVE` as well?

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [November 2, 2023, 10:10pm UTC](https://discourse.cmake.org/t/whole-archive-with-transitive-dependencies/9344/3 "2023-11-02T22:10:44Z")

</div>

As I already explain in issue [#24504](https://gitlab.kitware.com/cmake/cmake/-/issues/24504), for now, because CMake do not have any knowledge about semantics attached to features provided by `$<LINK_LIBRARY>` genex, it is not possible to do any specific treatment.

And I strongly disagree to start to hack the code to resolve a specific problem. The only valid and long-term solution is to elaborate some way to attach semantics to the features, generic enough to be useful for **any** feature (and usable by users which can introduce features as well).

---

<div class="post-metadata">

### Author: ![kolrami](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kolrami/32/3970_2.png) [@kolrami](https://discourse.cmake.org/u/kolrami)
#### Post date: [November 3, 2023, 8:21pm UTC](https://discourse.cmake.org/t/whole-archive-with-transitive-dependencies/9344/4 "2023-11-03T20:21:41Z")

</div>

Thank you for the replies @ben.boeckel and @marc.chevrier . I fully agree that a “hack” for this situation is not what we want. But still I think from user’s perspective it is quite unexpected that using the WHOLE\_ARCHIVE option causes linking errors due to the library being linked twice.
