How can I add dlib in cmake with findpackage?
Asked Answered
H

3

6

This is my cmakelists.txt:

project( WolframMachine )                                    
cmake_minimum_required(VERSION 3.1)
set (CMAKE_CXX_STANDARD 11)
set(CMAKE_SUPPRESS_REGENERATION true)
include(ExternalProject)
set(Boost_INCLUDE_DIR "C:/boost_1_66_0")
set(Boost_LIBRARY_DIR "C:/boost_1_66_0/lib64-msvc-14.0")
SET("OpenCV_DIR" "C:/opencv-3.4.1/build")
SET(dlib_DIR "C:/dlib-19.13/")  # <============ DLIB
find_package( OpenCV COMPONENTS core imgproc highgui aruco optflow plot REQUIRED )
find_package(dlib REQUIRED)  # <============ DLIB
add_subdirectory(dlibtest)

Running cmake-gui gives me following:

enter image description here

setting dlib_DIR manually doesn't help. How can I fix this?

UPD: tried other dlib_DIR values with no success:

SET(dlib_DIR "C:/dlib-19.13/build/dlib/CMakeFiles/Export/lib/cmake/dlib")

gives same error:

enter image description here

and setting

SET(dlib_DIR "C:/dlib-19.13/build/dlib/config")

gives another meaningless error:

enter image description here

Hyperactive answered 26/5, 2018 at 16:48 Comment(6)
setting dlib_DIR manually doesn't help. - Set dlib_DIR variable to the directory, containing dlibConfig.cmake file. Directory probably ends with cmake/dlib.Factorial
setting dlib to that folder gives another errorHyperactive
Which error it gives?Factorial
@Tsyvarev, please see my update.Hyperactive
1) What are the contents of dlib_DIR? The actual file contents, not the path. 2) Please include your errors as text, not as images.Junkie
It smells like you have just built, but have not installed dlib.Factorial
H
1

It looks like dlib was not designed to add it with find_package. What you have to do is to add it as subdirectory:

add_subdirectory(C:/dlib-19.13 dlib_build)

and also add resulting libs to your binary:

target_link_libraries( ${CUR_PROJECT_NAME} ${OpenCV_LIBS} ${Boost_LIBRARIES} dlib::dlib)
# ---------------------------------------------------------------------------^^^^^^^^^^
Hyperactive answered 31/5, 2018 at 18:4 Comment(2)
DLib works fine with find_package. We use it in our project and it works fine. Our CMakeLists.txt contains the following 3 lines: find_package(DLIB REQUIRED), include_directories(${DLIB_INCLUDE_DIRECTORY}), target_link_libraries(your_project ${DLIB_LIBRARIES} dlib).Nigritude
This solution suggested by Dlib and used in examples/CMakeLists.txt. The only problem is whenever you clean your project, Dlib will be cleaned also and it should be compiled again!Muriate
P
1

Here are the steps I followered,

For installing the dlib, change the link to the desired version

wget http://dlib.net/files/dlib-19.6.tar.bz2 
tar xvf dlib-19.6.tar.bz2
cd dlib-19.6/
mkdir build
cd build
cmake ..
cmake --build . --config Release
sudo make install
sudo ldconfig

In your project,

find_package(dlib REQUIRED)

target_link_libraries(try_convex  dlib::dlib)
Patina answered 5/12, 2020 at 14:16 Comment(0)
C
0

Can you try these in top level CMakeLists.txt?

SET(dlib_ROOT "C:/dlib-19.13/")

or

SET(dlib_DIR "C:/dlib-19.13/" CACHE STRING "")
Civilize answered 5/6, 2018 at 11:25 Comment(1)
Setting the dlib path manually is really not the correct way. If dlib was installed correctly, cmake would find it. If you are using Windows: MSYS2 supports dlib + cmake out of the box.Nigritude

© 2022 - 2024 — McMap. All rights reserved.