# trouble compiling dlib within my own project

**URL:** https://discourse.cmake.org/t/trouble-compiling-dlib-within-my-own-project/15347
**Category:** Usage
**Created:** [November 26, 2025, 10:23am UTC](https://discourse.cmake.org/t/trouble-compiling-dlib-within-my-own-project/15347 "2025-11-26T10:23:49Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [November 26, 2025, 10:23am UTC](https://discourse.cmake.org/t/trouble-compiling-dlib-within-my-own-project/15347/1 "2025-11-26T10:23:49Z")

</div>

Hi,

So far I used dlib by compiling and installing a standalone version which I imported through find\_package.

But I’m needing now to compile it directly inside my project, in order to propagate some specific compilation options.

What I tried is (following [examples/CMakeLists.txt](https://dlib.net/examples/CMakeLists.txt.html)):

```cmake
add_subdirectory(Path_2_dlib ${CMAKE_BINARY_DIR}/dlib)
target_link_libraries(MyLib PUBLIC dlib::dlib)

```

But on configuration, I’m getting:

> CMake Error: install(EXPORT “MyLibTargets” …) includes target “MyLib” which requires target “dlib” that is not in any export set.

Why and how can I fix that?

Regards,  
A.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [November 26, 2025, 9:24pm UTC](https://discourse.cmake.org/t/trouble-compiling-dlib-within-my-own-project/15347/2 "2025-11-26T21:24:04Z")

</div>

That error is telling you that `MyLib` links to `dlib::dlib`, and because `dlib::dlib` isn’t an imported library and rather is built by your project, exporting `MyLib` also requires exporting `dlib::dlib`. If you don’t export `dlib::dlib`, your export set would be incomplete and consumers couldn’t link to your `MyLib` target.

The “how can I fix that” part is tricky. Taking a step back, what are you expecting consumers to do if they want to link to your `MyLib` target? Are you expecting them to provide dlib, or are you trying to include dlib in your package that provides `MyLib`? If the latter, consider that some consumers might not want your version of dlib, they might want to get dlib from somewhere else (e.g. from conan).

This is one of the down sides to building a dependency directly as part of your own project. It isn’t typically a good fit when your main project produces libraries that you want to package up and make available for others to consume. You’re better off using a package manager to bring in pre-built dependencies for that (and don’t force your choice of package manager on consumers of your library).

---

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [November 27, 2025, 8:14am UTC](https://discourse.cmake.org/t/trouble-compiling-dlib-within-my-own-project/15347/3 "2025-11-27T08:14:19Z")

</div>

Hi,

Actually, for customers I’d link to the third party version but for now, I need to build it with my own compilation options to use temporarily with a sanitizer (with msvc and I’d like not to mess with dlib provided cmakelist).

Regards
