# A CMake way to embed a library in another?

**URL:** https://discourse.cmake.org/t/a-cmake-way-to-embed-a-library-in-another/7534
**Category:** Usage
**Created:** [February 23, 2023, 5:26pm UTC](https://discourse.cmake.org/t/a-cmake-way-to-embed-a-library-in-another/7534 "2023-02-23T17:26:08Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![JRR](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/ecccb3/32.png) [@JRR](https://discourse.cmake.org/u/JRR)
#### Post date: [February 23, 2023, 5:26pm UTC](https://discourse.cmake.org/t/a-cmake-way-to-embed-a-library-in-another/7534/1 "2023-02-23T17:26:08Z")

</div>

We have a product that creates a few libraries that are in turn combined with more code to make a _super library_.

_For example, we have static libraries lib-A and lib-B that are combined with even more source code to make static lib-C._

When creating `lib-C` it integrates with `lib-A` and `lib-B` using

```auto
target_link_libraries(...PRIVATE...)

```

  

We also have extra custom logic that causes the objects from `lib-A` and `lib-B` to be embedded in `lib-C`. So in the end `lib-C` has all of it’s object files as well as all of the object files from `lib-A` and `lib-B`.

We then export `lib-C` using the instructions from the [“Importing and Exporting Guide”](https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html).

However, we’re hitting an unexpected problem. Our executables that link with `lib-C` are raising an error that they cannot find `lib-A` or `lib-B`.

For example:

```auto
LINK : fatal error LNK1181: cannot open input file 'lib-A_64.lib' [C:\...\foo_64.vcxproj]

```

  

When I dug into this I found that this is most likely because of the exported library for `lib-C`. The generated `lib-C_64Targets.cmake` has logic such as the following:

```auto
set_target_properties(lib-C_64 PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
  INTERFACE_LINK_LIBRARIES "OpenMP::OpenMP_CXX;\$<LINK_ONLY:lib-A_64>;\$<LINK_ONLY:lib-B_64>"
)

```

I believe it’s the presense of these `LINK_ONLY` entries in the `INTERFACE_LINK_LIBRARIES` properties.

I know that, I can manually remove these values from the `INTERFACE_LINK_LIBRARIES` after embedding the libraries. I can do so first reading the property, adjusting it and then writing it back. However, I would like to learn if there is a more elegant “_CMake_” way of achieving my goal.

Can you teach me of a different or better way?

Thank you.

---

<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 23, 2023, 7:57pm UTC](https://discourse.cmake.org/t/a-cmake-way-to-embed-a-library-in-another/7534/2 "2023-02-23T19:57:41Z")

</div>

No, CMake does not have such an abstraction. See [this issue](https://gitlab.kitware.com/cmake/cmake/-/issues/22679).
