无法使用全局安装的Dlib编译Dlib示例

时间:2017-10-10 05:46:07

标签: c++ cmake dlib

我使用此命令sudo cmake --build . --target install --config Release编译并安装Dlib作为全局共享库,然后进行双重检查以确保路径/usr/local/include/dlib中包含必要的文件。

我修改了dlib/examples/CMakeLists.txt以便使用共享库进行编译,下面的大多数行是原始的:

cmake_minimum_required(VERSION 2.8.12)
project(examples)

# Modified lines [1]
#include(../dlib/cmake)
find_package(dlib REQUIRED)
include_directories(${dlib_INCLUDE_DIRS})

macro(add_example name)
   add_executable(${name} ${name}.cpp)
   # Modified lines [2]
   #target_link_libraries(${name} dlib::dlib )
   target_link_libraries(${name} ${dlib_INCLUDE_LIBS})
endmacro()

macro(add_gui_example name)
   if (DLIB_NO_GUI_SUPPORT)
      message("No GUI support, so we won't build the ${name} example.")
   else()
      add_example(${name})
   endif()
endmacro()

add_gui_example(face_detection_ex)

删除原始CMakeLists.txt的其余部分。

以下是输出日志的一部分(删除了重复部分):

[ 50%] Building CXX object CMakeFiles/face_detection_ex.dir/face_detection_ex.cpp.o
[100%] Linking CXX executable face_detection_ex
CMakeFiles/face_detection_ex.dir/face_detection_ex.cpp.o: In function `dlib::entropy_decoder_model_kernel_5<257ul, dlib::entropy_decoder_kernel_2, 200000ul, 4ul>::decode(unsigned long&)':
face_detection_ex.cpp:(.text._ZN4dlib30entropy_decoder_model_kernel_5ILm257ENS_24entropy_decoder_kernel_2ELm200000ELm4EE6decodeERm[_ZN4dlib30entropy_decoder_model_kernel_5ILm257ENS_24entropy_decoder_kernel_2ELm200000ELm4EE6decodeERm]+0x175): undefined reference to `dlib::entropy_decoder_kernel_2::get_target(unsigned int)'

face_detection_ex.cpp:(.text._ZN4dlib30entropy_decoder_model_kernel_5ILm257ENS_24entropy_decoder_kernel_2ELm200000ELm4EE6decodeERm[_ZN4dlib30entropy_decoder_model_kernel_5ILm257ENS_24entropy_decoder_kernel_2ELm200000ELm4EE6decodeERm]+0x215): undefined reference to `dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)'

face_detection_ex.cpp:(.text._ZNK4dlib10png_loader9get_imageINS_7array2dIhNS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_[_ZNK4dlib10png_loader9get_imageINS_7array2dIhNS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_]+0x7a): undefined reference to `dlib::png_loader::is_gray() const'

face_detection_ex.cpp:(.text._ZN4dlib30entropy_decoder_model_kernel_5ILm256ENS_24entropy_decoder_kernel_2ELm200000ELm4EE6decodeERm[_ZN4dlib30entropy_decoder_model_kernel_5ILm256ENS_24entropy_decoder_kernel_2ELm200000ELm4EE6decodeERm]+0x175): undefined reference to `dlib::entropy_decoder_kernel_2::get_target(unsigned int)'

face_detection_ex.cpp:(.text._ZNK4dlib24compress_stream_kernel_1INS_30entropy_encoder_model_kernel_5ILm257ENS_24entropy_encoder_kernel_2ELm200000ELm4EEENS_30entropy_decoder_model_kernel_5ILm257ENS_24entropy_decoder_kernel_2ELm200000ELm4EEENS_5crc32EE10decompressERSiRSo[_ZNK4dlib24compress_stream_kernel_1INS_30entropy_encoder_model_kernel_5ILm257ENS_24entropy_encoder_kernel_2ELm200000ELm4EEENS_30entropy_decoder_model_kernel_5ILm257ENS_24entropy_decoder_kernel_2ELm200000ELm4EEENS_5crc32EE10decompressERSiRSo]+0x7a0): undefined reference to `dlib::entropy_decoder_kernel_2::get_target(unsigned int)'

face_detection_ex.cpp:(.text._ZNK4dlib24compress_stream_kernel_1INS_30entropy_encoder_model_kernel_5ILm257ENS_24entropy_encoder_kernel_2ELm200000ELm4EEENS_30entropy_decoder_model_kernel_5ILm257ENS_24entropy_decoder_kernel_2ELm200000ELm4EEENS_5crc32EE10decompressERSiRSo[_ZNK4dlib24compress_stream_kernel_1INS_30entropy_encoder_model_kernel_5ILm257ENS_24entropy_encoder_kernel_2ELm200000ELm4EEENS_30entropy_decoder_model_kernel_5ILm257ENS_24entropy_decoder_kernel_2ELm200000ELm4EEENS_5crc32EE10decompressERSiRSo]+0x7bf): undefined reference to `dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)'

face_detection_ex.cpp:(.text._ZNK4dlib24compress_stream_kernel_1INS_30entropy_encoder_model_kernel_5ILm257ENS_24entropy_encoder_kernel_2ELm200000ELm4EEENS_30entropy_decoder_model_kernel_5ILm257ENS_24entropy_decoder_kernel_2ELm200000ELm4EEENS_5crc32EE10decompressERSiRSo[_ZNK4dlib24compress_stream_kernel_1INS_30entropy_encoder_model_kernel_5ILm257ENS_24entropy_encoder_kernel_2ELm200000ELm4EEENS_30entropy_decoder_model_kernel_5ILm257ENS_24entropy_decoder_kernel_2ELm200000ELm4EEENS_5crc32EE10decompressERSiRSo]+0x895): undefined reference to `dlib::entropy_decoder_kernel_2::~entropy_decoder_kernel_2()'

CMakeFiles/face_detection_ex.dir/face_detection_ex.cpp.o: In function `dlib::get_serialized_frontal_faces[abi:cxx11]()':
face_detection_ex.cpp:(.text._ZN4dlib28get_serialized_frontal_facesB5cxx11Ev[_ZN4dlib28get_serialized_frontal_facesB5cxx11Ev]+0x9f1c): undefined reference to `dlib::base64::~base64()'
CMakeFiles/face_detection_ex.dir/face_detection_ex.cpp.o: In function `void dlib::load_dng<dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> >&, std::istream&)':
face_detection_ex.cpp:(.text._ZN4dlib8load_dngINS_7array2dIhNS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_RSi[_ZN4dlib8load_dngINS_7array2dIhNS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_RSi]+0x2f68): undefined reference to `dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)'
face_detection_ex.cpp:(.text._ZN4dlib8load_dngINS_7array2dIhNS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_RSi[_ZN4dlib8load_dngINS_7array2dIhNS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_RSi]+0x342d): undefined reference to `dlib::entropy_decoder_kernel_2::get_target(unsigned int)'
face_detection_ex.cpp:(.text._ZN4dlib8load_dngINS_7array2dIhNS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_RSi[_ZN4dlib8load_dngINS_7array2dIhNS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_RSi]+0x3c03): undefined reference to `dlib::entropy_decoder_kernel_2::set_stream(std::istream&)'
face_detection_ex.cpp:(.text._ZN4dlib8load_dngINS_7array2dIhNS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_RSi[_ZN4dlib8load_dngINS_7array2dIhNS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_RSi]+0x43a0): undefined reference to `dlib::entropy_decoder_kernel_2::~entropy_decoder_kernel_2()'

face_detection_ex.cpp:(.text.startup+0x3e2): undefined reference to `dlib::image_window::image_window()'
face_detection_ex.cpp:(.text.startup+0x98a): undefined reference to `dlib::image_window::clear_overlay()'
face_detection_ex.cpp:(.text.startup+0xac3): undefined reference to `dlib::scrollable_region::set_total_rect_size(unsigned long, unsigned long)'

collect2: error: ld returned 1 exit status
CMakeFiles/face_detection_ex.dir/build.make:94: recipe for target 'face_detection_ex' failed
make[2]: *** [face_detection_ex] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/face_detection_ex.dir/all' failed
make[1]: *** [CMakeFiles/face_detection_ex.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

1 个答案:

答案 0 :(得分:0)

我找到了原因,那是因为我做了一个错字target_link_libraries(my_target ${dlib_INCLUDE_LIBS})。虽然必须是dlib_LIBRARIESdlib_LIBS,而不是dlib_INCLUDE_LIBS

正确的CMakeLists.txt是:

cmake_minimum_required(VERSION 2.8.12)
project(examples)

# Fix error "cannot find -lopencv_dep_cudart"
set(CUDA_USE_STATIC_CUDA_RUNTIME OFF)

# Modified lines [1]
# include(../dlib/cmake)
find_package(dlib REQUIRED)
include_directories(${dlib_INCLUDE_DIRS})

macro(add_example name)
   add_executable(${name} ${name}.cpp)
   # Modified lines [2]
   # target_link_libraries(${name} dlib::dlib )
   target_link_libraries(${name} ${dlib_LIBS})
endmacro()

macro(add_gui_example name)
   if (DLIB_NO_GUI_SUPPORT)
      message("No GUI support, so we won't build the ${name} example.")
   else()
      add_example(${name})
   endif()
endmacro()

add_gui_example(face_detection_ex)