trouble compiling dlib within my own project

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):

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.

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).

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