# the usage of target\_include\_directories vs target\_link\_libraries

**URL:** https://discourse.cmake.org/t/the-usage-of-target-include-directories-vs-target-link-libraries/7914
**Category:** Usage
**Created:** [April 16, 2023, 5:17am UTC](https://discourse.cmake.org/t/the-usage-of-target-include-directories-vs-target-link-libraries/7914 "2023-04-16T05:17:17Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [April 17, 2023, 7:49am UTC](https://discourse.cmake.org/t/the-usage-of-target-include-directories-vs-target-link-libraries/7914/6 "2023-04-17T07:49:16Z")

</div>

Hi IMHO, I partially agree for the executable part but not for the library one.  
First of all it does not depend on the shared/static status.  
Let say a lib A depends on a lib B.  
If the headers of A that may be included by an application that links A contains symbols from B then `target_link_libraries(A PUBLIC B)`  
otherwise `target_link_libraries(A PRIVATE B)`  
another situation may arise: B symbols are only present in A headers but are not used for A sources.  
then `target_link_libraries(A INTERFACE B)`

for applications I agree that `PUBLIC` or `PRIVATE` should not make a difference, yet its cleaner then to use `PRIVATE`.

I sum up it in the following way (`for target_compile_definitions` and `target_link_libraries`):  
`PRIVATE`: the target uses the definition/dependency only to be build, not its clients  
`PUBLIC`: the target uses the definition/dependency when it is built, its clients also use it  
`INTERFACE`: the target does not uses the definition/dependency when it is built, but its clients use it

---

_[View the full topic](https://discourse.cmake.org/t/the-usage-of-target-include-directories-vs-target-link-libraries/7914)._
