# WHOLE\_ARCHIVE portability

**URL:** <https://discourse.cmake.org/t/whole-archive-portability/13154>\
**Category:** Code\
**Created:** [December 8, 2024, 5:35pm UTC](https://discourse.cmake.org/t/whole-archive-portability/13154 "2024-12-08T17:35:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![petk](https://discourse.cmake.org/user_avatar/discourse.cmake.org/petk/32/4555_2.png) [@petk](https://discourse.cmake.org/u/petk)\
**Post date:** [December 8, 2024, 5:35pm UTC](https://discourse.cmake.org/t/whole-archive-portability/13154/1 "2024-12-08T17:35:18Z")

</div>

Hello,

Does anyone perhaps know how portable is the `WHOLE_ARCHIVE` feature when linking static libraries and where it could cause issues? It uses the linker flags such as `--whole-archive`,  
`/WHOLEARCHIVE` etc.

```cmake
target_link_libraries(app PRIVATE $<LINK_LIBRARY:WHOLE_ARCHIVE,foo>)

```

Or is it still better to go with `OBJECT` libraries instead and linking target objects separately?

Because it seems to me there is quite common issue, where linking a project `STATIC` library into executable doesn’t add unused objects to the final binary. For example, if they are used only in some `SHARED` library later on (which is loaded dynamically to the executable), or when linking other `STATIC` libraries created during the build to the main project `STATIC` library. In such cases, the whole archive feature would be very useful.

In other words, from a linker and compiler point of view, is there any difference in the produced binary between this:

```cmake
add_library(foo STATIC foo.c ...)
add_executable(app app.c ...)
target_link_libraries(app PRIVATE $<LINK_LIBRARY:WHOLE_ARCHIVE,foo>)

```

and this:

```cmake
add_library(foo OBJECT foo.c ...)
add_executable(app app.c ...)
target_link_libraries(app PRIVATE foo)

```

Thank you for any idea or pointer here.
