# PRIVATE target\_link\_libraries on header only imported library results in linkage requirement

**URL:** https://discourse.cmake.org/t/private-target-link-libraries-on-header-only-imported-library-results-in-linkage-requirement/1350
**Category:** Usage
**Created:** [June 8, 2020, 4:37pm UTC](https://discourse.cmake.org/t/private-target-link-libraries-on-header-only-imported-library-results-in-linkage-requirement/1350 "2020-06-08T16:37:56Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Kerstin\_Keller](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kerstin_keller/32/180_2.png) [@Kerstin\_Keller](https://discourse.cmake.org/u/Kerstin_Keller)
#### Post date: [June 8, 2020, 4:37pm UTC](https://discourse.cmake.org/t/private-target-link-libraries-on-header-only-imported-library-results-in-linkage-requirement/1350/1 "2020-06-08T16:37:56Z")

</div>

Let’s assume I have a library that links privately to an imported, header only library:

FindAsio.cmake (unfortunately does not export itself)

```auto
add_library(asio::asio INTERFACE IMPORTED)
set_target_properties(asio::asio PROPERTIES
      INTERFACE_INCLUDE_DIRECTORIES ${Asio_INCLUDE_DIR}
      INTERFACE_COMPILE_DEFINITIONS ASIO_STANDALONE)

```

and then the project of choice:

```auto
add_library (fineftp all_my_sources.cpp)
add_library (fineftp::fineftp ALIAS fineftp)

target_link_libraries(fineftp
    PRIVATE
        asio::asio
        Threads::Threads
)

```

Exporting this library with CMake leads to the following statements in `fineftpTargets.cmake`:

```auto
add_library(fineftp::server STATIC IMPORTED)

set_target_properties(fineftp::server PROPERTIES
  INTERFACE_COMPILE_DEFINITIONS "ASIO_STANDALONE;__USE_FILE_OFFSET64=1"
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
  INTERFACE_LINK_LIBRARIES "\$<LINK_ONLY:asio::asio>;\$<LINK_ONLY:Threads::Threads>"
)

```

This requires the user to locate asio on their machine, too, though it’s a private requirement of a header only library, e.g. there will be no linkage.

Not locating `asio` as a consumer of `fineftp-server` leads to the following CMake Error.

```auto
CMake Error at CMakeLists.txt:9 (add_executable):
  Target "fineftp_example" links to target "asio::asio" but the target was
  not found. Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

```

How can I avoid this usage requirement? Is this a CMake bug? Or is it necessary because `asio::asio` could have other transitive dependencies which need to be linked?

The following project has this problem, try building / installing it and then building the samples against the installed version:

> **[continental/fineftp-server](https://github.com/continental/fineftp-server)**
>
> C++ FTP Server Library for Windows & Linux. Contribute to continental/fineftp-server development by creating an account on GitHub.

---

<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: [June 8, 2020, 5:16pm UTC](https://discourse.cmake.org/t/private-target-link-libraries-on-header-only-imported-library-results-in-linkage-requirement/1350/2 "2020-06-08T17:16:45Z")

</div>

It is added to the list because `fineftp` is a static library. We could probably drop interface targets from the required export set of static and object libraries if the dependent target has no link interface (link options or link libraries).

Cc: @brad.king

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [June 8, 2020, 5:58pm UTC](https://discourse.cmake.org/t/private-target-link-libraries-on-header-only-imported-library-results-in-linkage-requirement/1350/3 "2020-06-08T17:58:11Z")

</div>

See [CMake Issue 15415](https://gitlab.kitware.com/cmake/cmake/-/issues/15415#note_333595) and its discussion of a [possible workaround](https://gitlab.kitware.com/cmake/cmake/-/issues/15415#note_634114).

---

<div class="post-metadata">

### Author: ![Kerstin\_Keller](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kerstin_keller/32/180_2.png) [@Kerstin\_Keller](https://discourse.cmake.org/u/Kerstin_Keller)
#### Post date: [June 9, 2020, 2:56pm UTC](https://discourse.cmake.org/t/private-target-link-libraries-on-header-only-imported-library-results-in-linkage-requirement/1350/4 "2020-06-09T14:56:40Z")

</div>

Ah thanks a lot for the feedback. I will try the workaround.
