如何让dlib中的face_detection_ex.cpp在c ++中工作?

时间:2016-09-20 20:50:02

标签: c++ cmake clion dlib

我是c ++的新手,很抱歉,如果有一个明显的解决方案,我就错过了。我试图在c ++中为dlib运行this示例代码。我收到了这个错误......

In file included from /Users/john/ClionProjects/dlib/examples/face_detection_ex.cpp:41:
In file included from /Users/john/ClionProjects/dlib/dlib/../dlib/gui_widgets.h:13:
In file included from /Users/john/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_widgets/widgets.h:9:
In file included from /Users/john/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_widgets/drawable.h:8:
In file included from /Users/john/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_widgets/../gui_core.h:14:
In file included from /Users/john/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_core/xlib.h:4:
/Users/john/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_core/gui_core_kernel_2.h:11:2: error: "DLIB_NO_GUI_SUPPORT is defined so you can't use the GUI code.  Turn DLIB_NO_GUI_SUPPORT off if you want to use it."
#error "DLIB_NO_GUI_SUPPORT is defined so you can't use the GUI code.  Turn DLIB_NO_GUI_SUPPORT off if you want to use it."
 ^
/Users/johnoberhauser/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_core/gui_core_kernel_2.h:12:2: error: "Also make sure you have libx11-dev installed on your system"
#error "Also make sure you have libx11-dev installed on your system"

我已尝试进入/dlib/CMakeLists.txt并添加

set(DLIB_NO_GUI_SUPPORT OFF)

我知道它找到了X11包,因为我没有收到来自cmake的消息(我刚刚安装了XQuartz)

另外,我使用Clion,所以我没有从命令行运行cmake。而且我在OSX上

编辑:我尝试删除使用gui的代码部分,只是为了查看它是否可行。但是我得到了这个错误:

Undefined symbols for architecture x86_64:
  "_USER_ERROR__missing_dlib_all_source_cpp_file__OR__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives", referenced from:
  _dlib_check_consistent_assert_usage in main.cpp.o
  "_cblas_saxpy", referenced from:
  dlib::blas_bindings::cblas_axpy(int, float, float const*, int, float*, int) in main.cpp.o
  "_cblas_sscal", referenced from:
  dlib::blas_bindings::cblas_scal(int, float, float*) in main.cpp.o
  "_dgesvd_", referenced from:
  dlib::lapack::binding::gesvd(char, char, int, int, double*, int, double*, double*, int, double*, int, double*, int) in main.cpp.o
  "_png_create_info_struct", referenced from:
  dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
  "_png_create_read_struct", referenced from:
  dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
  "_png_destroy_read_struct", referenced from:
  dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
  dlib::png_loader::~png_loader() in libdlib.a(png_loader.cpp.o)
  dlib::png_loader::~png_loader() in libdlib.a(png_loader.cpp.o)
  "_png_get_bit_depth", referenced from:
  dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
  "_png_get_color_type", referenced from:
  dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
  "_png_get_image_height", referenced from:
  dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
  "_png_get_image_width", referenced from:
  dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
  "_png_get_rows", referenced from:
  dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
  "_png_init_io", referenced from:
  dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
  "_png_read_png", referenced from:
  dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
  "_png_set_longjmp_fn", referenced from:
  dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
  dlib::png_loader_user_error_fn_silent(png_struct_def*, char const*) in libdlib.a(png_loader.cpp.o)
  "_png_set_palette_to_rgb", referenced from:
  dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
  "_png_set_sig_bytes", referenced from:
  dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
  "_png_sig_cmp", referenced from:
  dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
ld: symbol(s) not found for architecture x86_64

我认为这与第一个问题是一个单独的问题,但是idk,也许它们是相关的?对于这个问题,我尝试过这里提到的内容https://github.com/davisking/dlib/issues/57我为第一部分创建了链接,然后将这些行添加到我的cmakelist.txt

include_directories(../../../../usr/X11/lib)
include_directories(../../../../usr/local/include)
include_directories(../../../../usr/local/lib)
但是,似乎没有解决这个问题。

编辑2:所以我认为这两个问题现在都已解决了。我想在上面提到的那些include_directories行中添加了帮助。另外,我开始从命令行使用cmake,而不是使用clion。

但是,我现在收到一个新错误:/

Undefined symbols for architecture x86_64:
  "dlib::base_window::invalidate_rectangle(dlib::rectangle const&)", referenced from:
  void dlib::image_display::set_image<dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > const&) in main.cpp.o
  "dlib::base_window::set_size(int, int)", referenced from:
  void dlib::image_window::set_image<dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > const&) in main.cpp.o
     "dlib::image_window::add_overlay(std::__1::vector<dlib::image_display::overlay_rect, std::__1::allocator<dlib::image_display::overlay_rect> > const&)", referenced from:
  void dlib::image_window::add_overlay<dlib::rgb_pixel>(std::__1::vector<dlib::rectangle, std::__1::allocator<dlib::rectangle> > const&, dlib::rgb_pixel) in main.cpp.o
  "dlib::image_window::clear_overlay()", referenced from:
  _main in main.cpp.o
  "dlib::image_window::image_window()", referenced from:
  _main in main.cpp.o
  "dlib::image_window::~image_window()", referenced from:
  _main in main.cpp.o
  "dlib::popup_menu_region::disable()", referenced from:
  void dlib::image_display::set_image<dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > const&) in main.cpp.o
  "dlib::scrollable_region::set_total_rect_size(unsigned long, unsigned long)", referenced from:
  void dlib::image_display::set_image<dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > const&) in main.cpp.o
  "dlib::draw_sunken_rectangle(dlib::canvas const&, dlib::rectangle const&, unsigned char)", referenced from:
      dlib::scrollable_region_style_default::draw_scrollable_region_border(dlib::canvas const&, dlib::rectangle const&, bool) const in main.cpp.o
  "dlib::image_display::get_image_display_rect() const", referenced from:
  void dlib::image_window::set_image<dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > const&) in main.cpp.o
ld: symbol(s) not found for architecture x86_64

一个又一个问题:/

编辑3:成功!所以我正在使用Clion进行编译。尽管clion中的cmake与我在命令行中使用的cmake版本相同,但由于某种原因它才起作用。

1 个答案:

答案 0 :(得分:1)

我通过删除“ cmake-build-debug”目录解决了这个问题。

然后重新打开项目(CLion将重新生成它)。

似乎还有一些缓存文件会影响编译。


但是在执行此步骤之前,请确保您确实安装了XQuartz。