# Fully Understand the concept of target\_link\_libraries

**URL:** https://discourse.cmake.org/t/fully-understand-the-concept-of-target-link-libraries/5062
**Category:** Usage
**Created:** [February 19, 2022, 6:46am UTC](https://discourse.cmake.org/t/fully-understand-the-concept-of-target-link-libraries/5062 "2022-02-19T06:46:32Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![two\_Two](https://discourse.cmake.org/user_avatar/discourse.cmake.org/two_two/32/2195_2.png) [@two\_Two](https://discourse.cmake.org/u/two_Two)
#### Post date: [February 19, 2022, 6:46am UTC](https://discourse.cmake.org/t/fully-understand-the-concept-of-target-link-libraries/5062/1 "2022-02-19T06:46:32Z")

</div>

I would like to fully understanding `target_link_libraries` .If I write

```auto
target_link_libraries( A B C )

```

In this case A(shared),B(static),C(shared) are libraries. I wonder:

1.What would the terminal command be in Ubuntu if I want to achieve same functionality?

2.What would system do for this statement, would system copy the content in B and C into A?

3.If I have to use A in other project, should I have to write `target_link_libraries( A B C )` in that CMakeLists.txt once again even if something might happened when first time building A ?

---

<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: [February 20, 2022, 2:13pm UTC](https://discourse.cmake.org/t/fully-understand-the-concept-of-target-link-libraries/5062/2 "2022-02-20T14:13:59Z")

</div>

> [@two\_Two](#):
>
> What would the terminal command be in Ubuntu if I want to achieve same functionality?

This really depends on what the link usage requirements `B` and `C` are. But assuming they are static libraries with no transitive dependencies or link option requirements, it just adds the full paths to the `.a` files to the link line.

> [@two\_Two](#):
>
> What would system do for this statement, would system copy the content in B and C into A?

Generally, the sections which contain (transitively) used code would be copied over. Unused sections will not be copied (without other flags like `--whole-archive`).

> [@two\_Two](#):
>
> If I have to use A in other project, should I have to write `target_link_libraries( A B C )` in that CMakeLists.txt once again even if something might happened when first time building A ?

If the `A` target is exported through CMake as a target, the usage requirements will follow it around. Though in the simplified case I assumed here, nothing else would be necessary (CMake or no), but this doesn’t hold if `B` or `C` are more complicated.
