# Linking tests for an INTERFACE library

**URL:** <https://discourse.cmake.org/t/linking-tests-for-an-interface-library/185>\
**Category:** Code\
**Created:** [November 12, 2019, 8:13am UTC](https://discourse.cmake.org/t/linking-tests-for-an-interface-library/185 "2019-11-12T08:13:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![martijntje](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@martijntje](https://discourse.cmake.org/u/martijntje)\
**Post date:** [November 12, 2019, 8:13am UTC](https://discourse.cmake.org/t/linking-tests-for-an-interface-library/185/1 "2019-11-12T08:13:17Z")

</div>

I am writing a header-only library - which I believe is best done using an INTERFACE target (there is nothing to be built after all). The library does have some dependencies, however, which I’d like to be visible from the generated target. Let’s assume the dependency I have is `boost::system`. I have the following CMakeLists.txt file for the library:

```
cmake_minimum_required(VERSION 3.13)
project(cmaketest)

find_package(Boost 1.48 COMPONENTS system REQUIRED)

add_library(testlibrary INTERFACE)
target_link_libraries(testlibrary INTERFACE boost::system)

add_subdirectory(test)

```

As you might have guessed, the `test` directory contains tests for the library, which contains the following CMakeLists.txt

```
find_package(Boost 1.48 COMPONENTS system REQUIRED)

add_executable(test main.cpp)
target_link_libraries(test testlibrary)

```

CMake is unhappy about this, and presents me the following error message:

```
CMake Error at test/CMakeLists.txt:3 (add_executable):
  Target "test" links to target "boost::system" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?

```

This error happens after CMake reports that it found boost twice (once for each CMakeLists.txt). So the `find_package` succeeds, yet it still fails because the target was not found.

What am I doing wrong here?

---

<div class="post-metadata">

**Author:** ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)\
**Post date:** [November 12, 2019, 8:52am UTC](https://discourse.cmake.org/t/linking-tests-for-an-interface-library/185/2 "2019-11-12T08:52:19Z")

</div>

> [@martijntje](#):
>
> boost::system

AFAIK, the name of the imported target is `Boost::system`, with a capital `B`.

---

<div class="post-metadata">

**Author:** ![martijntje](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@martijntje](https://discourse.cmake.org/u/martijntje)\
**Post date:** [November 12, 2019, 8:59am UTC](https://discourse.cmake.org/t/linking-tests-for-an-interface-library/185/3 "2019-11-12T08:59:21Z")

</div>

Wow, that was a silly mistake that took me _way_ too much time. Thanks for your help!
