# add\_dependencies could not able to find system default libraries in 3.28.3

**URL:** https://discourse.cmake.org/t/add-dependencies-could-not-able-to-find-system-default-libraries-in-3-28-3/10670
**Category:** Usage
**Tags:** os:linux
**Created:** [April 16, 2024, 6:41am UTC](https://discourse.cmake.org/t/add-dependencies-could-not-able-to-find-system-default-libraries-in-3-28-3/10670 "2024-04-16T06:41:54Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![ramana](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/b4bc9f/32.png) [@ramana](https://discourse.cmake.org/u/ramana)
#### Post date: [April 16, 2024, 6:41am UTC](https://discourse.cmake.org/t/add-dependencies-could-not-able-to-find-system-default-libraries-in-3-28-3/10670/1 "2024-04-16T06:41:54Z")

</div>

In the cmake 3.28.3, when I give library ( example here is libdl.so.2) , in the add\_dependencies, its throwing an error: The dependency target “dl” of target “xxxx” does not exist.  
add\_dependencies(xxxx zzzz dl)  
The dl library is there in the system: libc6:amd64: /usr/lib/x86\_64-linux-gnu/libdl.so.2

How to solve this issue.

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [April 16, 2024, 8:54am UTC](https://discourse.cmake.org/t/add-dependencies-could-not-able-to-find-system-default-libraries-in-3-28-3/10670/2 "2024-04-16T08:54:05Z")

</div>

You need target\_link\_libraries() instead of add\_dependencies(). The latter only takes cmake targets as arguments.

---

<div class="post-metadata">

### Author: ![ramana](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/b4bc9f/32.png) [@ramana](https://discourse.cmake.org/u/ramana)
#### Post date: [April 16, 2024, 10:16am UTC](https://discourse.cmake.org/t/add-dependencies-could-not-able-to-find-system-default-libraries-in-3-28-3/10670/3 "2024-04-16T10:16:59Z")

</div>

Thanks for your reply. There is already one target\_link\_libraries(xxxx glog gflags yyyy …) there, and when modified as per your advice,  
target\_link\_libraries(xxxx glog gflags yyyy zzzz, dl)  
its throwing the following error:  
Target “zzzz” of type UTILITY may not be linked into another target. One  
may link only to INTERFACE, OBJECT, STATIC or SHARED libraries, or to  
executables with the ENABLE\_EXPORTS property set.  
I tried with separate target\_link\_libraries(xxxx zzzz, dl)  
as well. Its throwing the same error  
Any idea how to fix on this? This error is not coming when I use add\_dependencies, but previous error is coming as I mentioned in my last mail.

Looking forward for your reply.

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [April 16, 2024, 11:32am UTC](https://discourse.cmake.org/t/add-dependencies-could-not-able-to-find-system-default-libraries-in-3-28-3/10670/4 "2024-04-16T11:32:17Z")

</div>

If I understand it right:

- `libdl.so.2` is a library on disk, external to your project.
- `zzzz` is a custom target in your project (created by `add_custom_target()`).
- You need your target `xxxx` to consume both.

`add_dependencies()` only accepts CMake targets as arguments, and introduces dependencies, but does not cause linking. `target_link_libraries()` accepts both targets and libraries, and causes them to be linked.

To link the library, use `target_link_libraries()`. To depend on a custom target (since these cannot be linked, they don’t correspond to anything linkable), use `add_dependencies()`. Put together:

```auto
add_dependencies(xxxx dl)
target_link_libraries(xxxx zzzz)

```

---

<div class="post-metadata">

### Author: ![ramana](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/b4bc9f/32.png) [@ramana](https://discourse.cmake.org/u/ramana)
#### Post date: [April 16, 2024, 2:18pm UTC](https://discourse.cmake.org/t/add-dependencies-could-not-able-to-find-system-default-libraries-in-3-28-3/10670/5 "2024-04-16T14:18:26Z")

</div>

add\_dependencies(xxxx dl) does not work on cmake 3.28.3 as I am seeing the same error. Probably this could not find the libdl.so file.  
The dependency target “dl” of target “xxxx” does not exist.  
I added the following changes and its not throwing any error. Are these changes are fine or do we have any alternative way to fix this issue.  
find\_library(DL libdl.so)  
add\_custom\_target(custom\_dl ${DL})  
add\_dependencies(xxxx custom\_dl)

here add\_custom\_target is compulsory or any other way we can do it?

Regards,

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [April 16, 2024, 2:52pm UTC](https://discourse.cmake.org/t/add-dependencies-could-not-able-to-find-system-default-libraries-in-3-28-3/10670/6 "2024-04-16T14:52:44Z")

</div>

I think you confused zzzz and dl in your code example. It should be:

```auto
add_dependencies(xxxx zzzz)
target_link_libraries(xxxx dl)

```

[/quote]

if zzzz is a custom target and libdl.so is the library file or a link to it (note: without .2 at the end)

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [April 16, 2024, 2:54pm UTC](https://discourse.cmake.org/t/add-dependencies-could-not-able-to-find-system-default-libraries-in-3-28-3/10670/7 "2024-04-16T14:54:54Z")

</div>

> [@ramana](#):
>
> find\_library(DL libdl.so)  
> add\_custom\_target(custom\_dl ${DL})  
> add\_dependencies(xxxx custom\_dl)

This does nothing useful.

---

<div class="post-metadata">

### Author: ![ramana](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/b4bc9f/32.png) [@ramana](https://discourse.cmake.org/u/ramana)
#### Post date: [April 16, 2024, 4:13pm UTC](https://discourse.cmake.org/t/add-dependencies-could-not-able-to-find-system-default-libraries-in-3-28-3/10670/8 "2024-04-16T16:13:29Z")

</div>

Thank you for an update. This is what I understood from your explanation. All installed libraries in the OS (like dl, gflags,… ) has to included using the target\_link\_libraries. And all the cmake generated targets need to be added using add\_dependencies.

There is one more Question. If my target depends on the header file (x.h), how can I add that.  
add\_executible(xxxx \< set of source files \>)  
target\_link\_libraries(xxxx yyyy zzzz)  
add\_dependencies(xxxx x.h)

This code snippet throwing the same error: The dependency target “x.h” of target “xxxx” does not  
exist.  
Note: this was working fine with 3.16.3 and seeing issues with 3.28.

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [April 16, 2024, 4:47pm UTC](https://discourse.cmake.org/t/add-dependencies-could-not-able-to-find-system-default-libraries-in-3-28-3/10670/9 "2024-04-16T16:47:06Z")

</div>

> [@ramana](#):
>
> Thank you for an update. This is what I understood from your explanation. All installed libraries in the OS (like dl, gflags,… ) has to included using the target\_link\_libraries. And all the cmake generated targets need to be added using add\_dependencies

Manually adding dependencies is rather the exception, e.g. when needing a specific build order.

It seems, you are unfamiliar with CMake, did you look at the tutorials?

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [April 16, 2024, 4:49pm UTC](https://discourse.cmake.org/t/add-dependencies-could-not-able-to-find-system-default-libraries-in-3-28-3/10670/11 "2024-04-16T16:49:53Z")

</div>

> [@ramana](#):
>
> There is one more Question. If my target depends on the header file (x.h), how can I add that.  
> add\_executible(xxxx \< set of source files \>)  
> target\_link\_libraries(xxxx yyyy zzzz)  
> add\_dependencies(xxxx x.h)

Header files are source files. There are exceptions for generated headers in other directories.
