# LINK\_LIBRARY:WHOLE\_ARCHIVE affects INTERFACE\_LINK\_LIBRARIES\_DIRECT, is that intentional?

**URL:** https://discourse.cmake.org/t/link-library-whole-archive-affects-interface-link-libraries-direct-is-that-intentional/9420
**Category:** Code
**Created:** [November 13, 2023, 4:24pm UTC](https://discourse.cmake.org/t/link-library-whole-archive-affects-interface-link-libraries-direct-is-that-intentional/9420 "2023-11-13T16:24:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ignus2](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ignus2/32/3075_2.png) [@ignus2](https://discourse.cmake.org/u/ignus2)
#### Post date: [November 13, 2023, 4:24pm UTC](https://discourse.cmake.org/t/link-library-whole-archive-affects-interface-link-libraries-direct-is-that-intentional/9420/1 "2023-11-13T16:24:40Z")

</div>

Given the following minimal project:

```auto
cmake_minimum_required(VERSION 3.25)
project(watest)
add_library(lib1 STATIC lib1.cpp)
add_library(lib2 STATIC lib2.cpp)
#target_link_libraries(lib2 PRIVATE lib1) # case 1: <-- use this OR the line below ONLY
set_property(TARGET lib2 PROPERTY INTERFACE_LINK_LIBRARIES_DIRECT lib1) # case 2: <-- use this OR the line above ONLY
add_executable(app main.cpp)
target_link_libraries(app PRIVATE $<LINK_LIBRARY:WHOLE_ARCHIVE,lib2>)

```

If I use `target_link_libraries(lib2 PRIVATE lib1)` ( **case 1** above) it works normally as expected, link line from compiling:

`link.exe ... /WHOLEARCHIVE:Debug\lib2.lib Debug\lib1.lib ...`

However if I use **case 2** : `set_property(TARGET lib2 PROPERTY INTERFACE_LINK_LIBRARIES_DIRECT lib1)`, and comment case 1 of course, then I get:

`link.exe ... /WHOLEARCHIVE:Debug\lib1.lib /WHOLEARCHIVE:Debug\lib2.lib ...`

Now lib1.lib also gets WHOLEARCHIVE-d, even though it’s not specified anywhere. Now why is that? I couldn’t find any hint in the documentation of INTERFACE\_LINK\_LIBRARIES\_DIRECT and/or the LINK\_LIBRARY genex that this is intended behavior.

Is this a bug, an undocumented feature or a side-effect (or something else)?

Note: the above is a hypothetical minimal example, obviously our actual use-case is much more complex…

---

<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 13, 2023, 5:04pm UTC](https://discourse.cmake.org/t/link-library-whole-archive-affects-interface-link-libraries-direct-is-that-intentional/9420/2 "2023-11-13T17:04:11Z")

</div>

This is clearly a bug. The library specified by `INTERFACE_LINK_LIBRARIES_DIRECT` property seems not injected at the right place in the direct dependencies of the final target.  
Can-you create an [issue](https://gitlab.kitware.com/cmake/cmake/-/issues) for this problem?  
Thanks.

---

<div class="post-metadata">

### Author: ![ignus2](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ignus2/32/3075_2.png) [@ignus2](https://discourse.cmake.org/u/ignus2)
#### Post date: [November 13, 2023, 5:48pm UTC](https://discourse.cmake.org/t/link-library-whole-archive-affects-interface-link-libraries-direct-is-that-intentional/9420/3 "2023-11-13T17:48:02Z")

</div>

Done: [https://gitlab.kitware.com/cmake/cmake/-/issues/25416](https://gitlab.kitware.com/cmake/cmake/-/issues/25416)
