Dlib: The imported target "dlib::dlib" references the file "/usr/lib/libdlib.a" but this file does not exist

Created on 9 Jan 2017  路  8Comments  路  Source: davisking/dlib

When including dlib in a custom project using CMake

find_package(dlib REQUIRED)
include_directories(${dlib_INCLUDE_DIRS})

cmakelist file :

cmake_minimum_required(VERSION 2.8.3)
project(gazr)

add_definitions(-std=c++11)


find_package(dlib REQUIRED)
include_directories(${dlib_INCLUDE_DIRS})

option(DEBUG "Enable debug visualizations" ON)
option(WITH_TOOLS "Compile sample tools" ON)
option(WITH_ROS "Build ROS nodes" OFF)

if(WITH_ROS)

find_package(catkin REQUIRED COMPONENTS 
    roscpp 
    tf
    std_msgs
    visualization_msgs
    sensor_msgs
    cv_bridge
    image_transport
    image_geometry
    )

    include_directories(${catkin_INCLUDE_DIRS})

   catkin_package(
   CATKIN_DEPENDS 
      tf
    DEPENDS OpenCV
   LIBRARIES 
   )
   endif()

   if(DEBUG)
   find_package(OpenCV COMPONENTS core imgproc calib3d highgui REQUIRED)
   else()
   find_package(OpenCV COMPONENTS core imgproc calib3d REQUIRED)
   endif()

    message(STATUS "OpenCV version: ${OpenCV_VERSION}")
  if(${OpenCV_VERSION} VERSION_GREATER 2.9.0)
  set(OPENCV3 TRUE)
  add_definitions(-DOPENCV3)
  endif()



 if(DEBUG)
add_definitions(-DHEAD_POSE_ESTIMATION_DEBUG)
 endif()

 include_directories(${OpenCV_INCLUDE_DIRS})

 add_library(gazr SHARED src/head_pose_estimation.cpp)
 target_link_libraries(gazr ${dlib_LIBRARIES} ${OpenCV_LIBRARIES})

if(WITH_ROS)

add_executable(estimate_focus src/estimate_focus.cpp)
target_link_libraries(estimate_focus ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})

add_executable(estimate src/head_pose_estimation_ros.cpp src/ros_head_pose_estimator.cpp)
target_link_libraries(estimate gazr ${catkin_LIBRARIES})

install(TARGETS estimate_focus gazr estimate
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

install(FILES
    launch/gazr.launch
    launch/gazr_gscam.launch
    calib/logitech-c920_640x360.ini
    share/shape_predictor_68_face_landmarks.dat
    DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
 )
 endif()

 if(WITH_TOOLS)

if(OPENCV3)
    find_package(OpenCV COMPONENTS core imgproc calib3d highgui imgcodecs videoio     REQUIRED)
  else()
    find_package(OpenCV COMPONENTS core imgproc calib3d highgui REQUIRED)
    endif()

 find_package(Boost COMPONENTS program_options REQUIRED)

  add_executable(gazr_benchmark_head_pose_single_frame       tools/benchmark_head_pose_estimation_single_frame.cpp)
target_link_libraries(gazr_benchmark_head_pose_single_frame gazr ${OpenCV_LIBRARIES})

add_executable(gazr_estimate_head_direction tools/estimate_head_direction.cpp)
target_link_libraries(gazr_estimate_head_direction gazr ${OpenCV_LIBRARIES} ${Boost_LIBRARIES})

add_executable(gazr_show_head_pose tools/show_head_pose.cpp)
target_link_libraries(gazr_show_head_pose gazr ${OpenCV_LIBRARIES} ${Boost_LIBRARIES})

endif()

I get the following error:

  CMake Error at /usr/lib/cmake/dlib/dlib.cmake:76 (message):
  The imported target "dlib::dlib" references the file

  "/usr/lib/libdlib.a"

  but this file does not exist.  Possible reasons include:

* The file was deleted, renamed, or moved to another location.

* An install or uninstall procedure did not complete successfully.

* The installation package was faulty and contained

   "/usr/lib/cmake/dlib/dlib.cmake"

   but not all the files it references.

 Call Stack (most recent call first):
/usr/lib/cmake/dlib/dlibConfig.cmake:35 (include)
CMakeLists.txt:7 (find_package)

Most helpful comment

I changed cmakelists these two lines :
find_package(dlib REQUIRED)
include_directories(${dlib_INCLUDE_DIRS})
into
set(DLIB_PATH "" CACHE PATH "Path to DLIB")
include(/home/ubuntu/dlib-19.0/dlib/cmake)

No need to make such changes. I have working projects that uses this lines and all fine

find_package(dlib REQUIRED)
include_directories(${dlib_INCLUDE_DIRS})
link_directories(${DLIB_LIBRARY_DIRS})

Looks like you dont have correctly installed Dlib in your system. Follow this steps and it should help

git clone https://github.com/davisking/dlib
cd dlib
mkdir build
cmake ..
sudo cmake --build . --target install

After this you should be able to use Dlib from CMakeLists.txt with no including cmake file from dlib

All 8 comments

Where does /usr/lib/cmake/dlib/dlibConfig.cmake come from? Some package manager or something?

I changed cmakelists these two lines :

find_package(dlib REQUIRED)
include_directories(${dlib_INCLUDE_DIRS})

into

set(DLIB_PATH "" CACHE PATH "Path to DLIB")
include(/home/ubuntu/dlib-19.0/dlib/cmake)

the cmake .. done without errors , but make shows this :

ubuntu@ubuntu:~/gazr/build$ make
[ 3%] Built target gazr
[ 4%] Linking CXX executable gazr_benchmark_head_pose_single_frame
CMakeFiles/gazr_benchmark_head_pose_single_frame.dir/tools/benchmark_head_pose_estimation_single_frame.cpp.o: In function _GLOBAL__sub_I_main': benchmark_head_pose_estimation_single_frame.cpp:(.text.startup+0x895): undefined reference toUSER_ERROR__missing_dlib_all_source_cpp_file__OR__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives_'
libgazr.so: undefined reference to dlib::base64::~base64()' libgazr.so: undefined reference todlib::entropy_decoder_kernel_2::get_target(unsigned int)'
libgazr.so: undefined reference to dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)' libgazr.so: undefined reference todlib::entropy_decoder_kernel_2::~entropy_decoder_kernel_2()'
libgazr.so: undefined reference to cblas_dgemm' libgazr.so: undefined reference todlib::base64::decode(std::istream&, std::ostream&) const'
libgazr.so: undefined reference to dgesvd_' libgazr.so: undefined reference todlib::entropy_decoder_kernel_2::entropy_decoder_kernel_2()'
libgazr.so: undefined reference to dlib::entropy_decoder_kernel_2::set_stream(std::istream&)' libgazr.so: undefined reference todlib::base64::base64()'
collect2: error: ld returned 1 exit status
CMakeFiles/gazr_benchmark_head_pose_single_frame.dir/build.make:104: recipe for target 'gazr_benchmark_head_pose_single_frame' failed
make[2]: * [gazr_benchmark_head_pose_single_frame] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/gazr_benchmark_head_pose_single_frame.dir/all' failed
make[1]:
[CMakeFiles/gazr_benchmark_head_pose_single_frame.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *
* [all] Error 2

Link to dlib. The examples/CMakeList.txt is an example of a working
CMakeLists.txt file.

now cmake .. is successful but ( make )is showing this error

ubuntu@ubuntu:~/gazr/build$ make

Scanning dependencies of target gazr
[ 12%] Building CXX object CMakeFiles/gazr.dir/src/head_pose_estimation.cpp.o
In file included from /home/tofi/gazr/src/head_pose_estimation.cpp:11:0:
/home/tofi/gazr/src/head_pose_estimation.hpp:5:25: fatal error: dlib/opencv.h: No such file or directory
#include
^
compilation terminated.

I changed cmakelists these two lines :
find_package(dlib REQUIRED)
include_directories(${dlib_INCLUDE_DIRS})
into
set(DLIB_PATH "" CACHE PATH "Path to DLIB")
include(/home/ubuntu/dlib-19.0/dlib/cmake)

No need to make such changes. I have working projects that uses this lines and all fine

find_package(dlib REQUIRED)
include_directories(${dlib_INCLUDE_DIRS})
link_directories(${DLIB_LIBRARY_DIRS})

Looks like you dont have correctly installed Dlib in your system. Follow this steps and it should help

git clone https://github.com/davisking/dlib
cd dlib
mkdir build
cmake ..
sudo cmake --build . --target install

After this you should be able to use Dlib from CMakeLists.txt with no including cmake file from dlib

Thanks for help. I'm confused now because dlib instructions says that :

Go into the examples folder and type:

  `mkdir build; cd build; cmake .. ; cmake --build .`

I done the instructions in your comment , how can I run dlib c++ examples ?

when I type ubuntu@ubuntu :~/dlib/build$ ./webcam_face_pose_ex

bash: ./webcam_face_pose_ex: No such file or directory

There are a lot of ways to compile C++ code. Dlib tries to be convenient and let you do it any way you want. The recommendations are only a small set of the possible ways you could do it. This thread had mentioned a few.

But if you aren't familiar with different C++ build methods you should just type exactly what the instructions say to do to run the examples.

The error @sarmadm reports here is still an issue in Ubuntu-16.04 universe repository (and maybe other distros too). The problem arises from the fact that the dlib.cmake file checks for a static library (add_library(dlib::dlib STATIC IMPORTED)) which cannot be found because it is not installed, as a quick dpkg-query -L libdlib-dev | grep grep ".*\.a" can reveal.

Was this page helpful?
0 / 5 - 0 ratings