# CMake target\_link\_libraries Dependencies

**URL:** https://discourse.cmake.org/t/cmake-target-link-libraries-dependencies/5564
**Category:** Usage
**Tags:** os:linux
**Created:** [April 28, 2022, 9:40am UTC](https://discourse.cmake.org/t/cmake-target-link-libraries-dependencies/5564 "2022-04-28T09:40:17Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![swaraj\_somala](https://discourse.cmake.org/user_avatar/discourse.cmake.org/swaraj_somala/32/1668_2.png) [@swaraj\_somala](https://discourse.cmake.org/u/swaraj_somala)
#### Post date: [April 28, 2022, 9:40am UTC](https://discourse.cmake.org/t/cmake-target-link-libraries-dependencies/5564/1 "2022-04-28T09:40:17Z")

</div>

I’m new to CMake and am attempting to figure out what the link requirements for ‘target link libraries’ are (Public,Private,Interface). I understand the concepts of public, private, and Interface dependencies, but I’m not sure how to apply them to my project.

I have a number of libraries in my project, and some of them have dependencies on each other.For instance, I have a logger library that is utilised in other libraries and is also used in the final application executable.

Reference:  
 ![image](https://discourse.cmake.org/uploads/default/original/2X/e/e627df9510f9ecd37a5019f40c58561bddfdbc6c.png)

So lib\_storage is reliant on logger, and App A is reliant on both lib\_storage and logger. If I make logger a public link to lib\_storage, App A will have access to logger as well. However, removing lib\_storage in the future will result in a logger build fault for App\_A. So, how do you attach logger to lib\_storage and logger to App A correctly?

---

<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: [April 28, 2022, 10:56am UTC](https://discourse.cmake.org/t/cmake-target-link-libraries-dependencies/5564/2 "2022-04-28T10:56:22Z")

</div>

If App\_A needs the logger itself, it should directly link regardless of whether a dependency brings it in as well.

The logic is:

- if you use a target, link it no matter what
- if you are header-only, use `INTERFACE`
- if using you implies using a target (e.g., you include a header from it in your public headers), use `PUBLIC`
- (corner cases that probably don’t apply here that I don’t have the time to explain)
- otherwise use `PRIVATE`
