# 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:** 4

<div class="post-metadata">

### Author: ![Joseph](https://discourse.cmake.org/user_avatar/discourse.cmake.org/joseph/32/3344_2.png) [@Joseph](https://discourse.cmake.org/u/Joseph)
#### Post date: [April 17, 2023, 5:11am UTC](https://discourse.cmake.org/t/the-usage-of-target-include-directories-vs-target-link-libraries/7914/4 "2023-04-17T05:11:17Z")

</div>

Your fixed code is correct. `tensorrt_cpp_api` is a lib, so link publically will always works no matter it is static or shared.

There are three modes for a target to link another lib, or include a directory: PUBLIC, PRIVATE and INTERFACE. For example: we have lib A and B, and a executable C. B links to A, and C links to B.

Pubic link:

```cmake
target_link_libraries(B PUBLIC A)
target_link_libraries(C PRIVATE B)

```

B will link to A, and C will be linked to both A and B.

Private link:

```cmake
target_link_libraries(B PRIVATE A)
target_link_libraries(C PRIVATE B)

```

B will link to A, and C will link to only B.

Interface link:

```cmake
target_link_libraries(B INTERFACE A)
target_link_libraries(C PRIVATE B)

```

B will not link to A, but C will link to both B and A.

In summary, PUBLIC is contagious, and PRIVATE is not contagious. INTERFACE is only used when B doesn’t actually requires A, but most targets that links to B requires A. INTERFACE is rarely used.

---

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