# How to properly add link dependencies for an INTERFACE library?

**URL:** <https://discourse.cmake.org/t/how-to-properly-add-link-dependencies-for-an-interface-library/9855>\
**Category:** Code\
**Created:** [January 15, 2024, 12:30pm UTC](https://discourse.cmake.org/t/how-to-properly-add-link-dependencies-for-an-interface-library/9855 "2024-01-15T12:30:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MattBas](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mattbas/32/4193_2.png) [@MattBas](https://discourse.cmake.org/u/MattBas)\
**Post date:** [January 15, 2024, 12:30pm UTC](https://discourse.cmake.org/t/how-to-properly-add-link-dependencies-for-an-interface-library/9855/1 "2024-01-15T12:30:28Z")

</div>

I have a header-only library that depends on some other library.

I would like to define my library in a way that targets linking to it also link to its dependencies.

This is the code I have looks something like this:

```cmake
# Library
add_library(my_lib INTERFACE)
target_link_libraries(my_lib INTERFACE other_lib)
target_include_directories(my_lib INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})

# Executable
add_executable(my_executable main.cpp)
target_link_libraries(my_executable PRIVATE my_lib)

```

With the code above, building `my_executable` gives linker error related to `other_lib`.

Linking `other_lib` explicitly works fine:

```cmake
target_link_libraries(my_executable PRIVATE my_lib other_lib)

```

But I’d like to avoid that and have CMake sort that out automatically without `my_executable` having to explicitly reference `other_lib`. How would I achieve this?

---

<div class="post-metadata">

**Author:** ![MattBas](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mattbas/32/4193_2.png) [@MattBas](https://discourse.cmake.org/u/MattBas)\
**Post date:** [January 15, 2024, 5:18pm UTC](https://discourse.cmake.org/t/how-to-properly-add-link-dependencies-for-an-interface-library/9855/2 "2024-01-15T17:18:50Z")

</div>

OK so I figure what the issue was, in my actual code `other_lib` was a few different libraries, apparently CMake keeps the order you write them in for the target specified in `target_link_libraries` but not for targets that link to it, I managed to fix it with `$<LINK_GROUP>`.
