# Does target\_link\_libraries(... PRIVATE) deduplicate?

**URL:** https://discourse.cmake.org/t/does-target-link-libraries-private-deduplicate/14275
**Category:** Code
**Tags:** tool:cmake
**Created:** [June 20, 2025, 10:33pm UTC](https://discourse.cmake.org/t/does-target-link-libraries-private-deduplicate/14275 "2025-06-20T22:33:51Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![bmcdonnell-fb](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bmcdonnell-fb/32/5561_2.png) [@bmcdonnell-fb](https://discourse.cmake.org/u/bmcdonnell-fb)
#### Post date: [June 20, 2025, 10:33pm UTC](https://discourse.cmake.org/t/does-target-link-libraries-private-deduplicate/14275/1 "2025-06-20T22:33:51Z")

</div>

I have an embedded C application with static libraries, where both the application and `lib1` use `lib2`. (`lib2` is not part of `lib1`’s interface.)

If my CMakeLists.txt includes something like this:

```auto
add_executable(app app.c)
add_library(lib1 STATIC lib1.c)
add_library(lib2 STATIC lib2.c)

target_link_libraries(app PRIVATE lib1)
target_link_libraries(app PRIVATE lib2)

target_link_libraries(lib1 PRIVATE lib2)

```

Will the build process necessarily deduplicate all linked code? In other words, is there any chance of duplicate code in the final compiled executable, if e.g. both `app` and `lib1` call the same function from `lib2`?

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [June 21, 2025, 10:21pm UTC](https://discourse.cmake.org/t/does-target-link-libraries-private-deduplicate/14275/2 "2025-06-21T22:21:16Z")

</div>

Since `lib1` and `lib2` are both static libraries, `app` should only end up with one copy of the code from `lib2`. It’s the linker’s job to resolve symbols needed by `app`’s object files. It will look through the `lib1` and `lib2` static libraries to resolve those symbols as needed. That’s a bit simplistic, but that’s the general idea.
