c++ - 为什么 Dlib 会编译 8000 多个函数?

标签 c++ opencv dlib

我正在使用 DlibOpenCVC++ Without CMakeVisual Studio 2015我试过 face_landmark_detection_ex使用笔记本电脑摄像头检测人脸的示例,效果很好。但我想知道为什么 Dlib说:164 of 8616 functions ( 1.9%) were compiled, the rest were copied from previous compilation.

我认为这个例子很简单,不需要 8000+ 函数就可以工作,我也想知道为什么它需要 57 个文件夹和 73 个 Header Files来自图书馆。

从Dlib官网的文档来看,依赖层级根本不清晰。

注意:我添加了source.cpp文件到我的项目,因为我得到 Linker Error ,这可以引用:

In most cases, to use this library all you have to do is extract it somewhere, make sure the folder containing the dlib folder is in your include path, and finally add dlib/all/source.cpp to your project. It is worth noting that most of dlib is "header-only" which means that, in many cases, you don't actually have to build dlib/all/source.cpp into your application. So if you don't get linker errors when you exclude dlib/all/source.cpp from your project then you don't need it.

修改后的 Source.cpp:

#include "../base64/base64_kernel_1.cpp"
#include "../entropy_decoder/entropy_decoder_kernel_2.cpp"
#include "../tokenizer/tokenizer_kernel_1.cpp"
#include "../unicode/unicode.cpp"
#include "../dir_nav/dir_nav_kernel_1.cpp"
#include "../logger/logger_kernel_1.cpp"
#include "../misc_api/misc_api_kernel_1.cpp"
#include "../threads/threaded_object_extension.cpp"
#include "../threads/threads_kernel_1.cpp"
#include "../threads/threads_kernel_shared.cpp"
#include "../timer/timer.cpp"

#include "../gui_widgets/fonts.cpp"
#include "../gui_widgets/widgets.cpp"
#include "../gui_widgets/drawable.cpp"
#include "../gui_widgets/canvas_drawing.cpp"
#include "../gui_widgets/style.cpp"
#include "../gui_widgets/base_widgets.cpp"
#include "../gui_core/gui_core_kernel_1.cpp"

enter image description here

最佳答案

使用 Dlib 的最佳方式 - 通过 CMake。 There is small tutorial how to include dlib in your project with CMake

使用 CMake 的另一种方式 - 您可以编译 Dlib 库并在您的项目中使用结果二进制文件 (.lib)。要生成 .lib 文件,您可以从 Visual Studio 开发人员命令提示符(从 dlib 文件夹)使用此命令:

md build
cd build
cmake .. -G"Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX=c:/where/to/put/release/library
cmake --build . --target install --config Release

编译完成后,您将在目标目录中获得 .lib 和 header 。如果您想调试您的程序 - 您应该再次编译并安装 dlib 到不同的目录:

cmake .. -G"Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX=c:/where/to/put/debug/library
cmake --build . --target install --config Debug

这将使您调试二进制文件。接下来,在基于 CMake 的应用程序项目中,您可以编写以下行:

cmake_minimum_required(VERSION 3.2)
find_package(dlib REQUIRED)
add_executable(example example.cpp)
target_link_libraries(example dlib::dlib)

你可以编译这个应用程序

md build
cd build
cmake .. -G"Visual Studio 14 2015 Win64" -DCMAKE_PREFIX_PATH=c:/where/to/put/release/library
cmake --build . --target install --config Release

和调试版本:

md build
cd build
cmake .. -G"Visual Studio 14 2015 Win64" -DCMAKE_PREFIX_PATH=c:/where/to/put/debug/library
cmake --build . --target install --config Debug

请注意,在编译 Dlib 时,您正在使用 CMAKE_INSTALL_PREFIX - 这是放置库的位置,在编译您的项目时,您正在使用 CMAKE_ PREFIX_PATH - 在哪里搜索 Dlib

正如您在此处看到的那样 - 有很多步骤,您可能会在每个阶段遇到错误,因此您可以简单地将“all/source.cpp”放入您的项目中(因为您已经完成)-仅此而已,它有效。使用 all/source 方式,您无需考虑不同的编译模式(调试/发布)、体系结构(x86/x64)、运行时链接(共享/静态/多线程...)、不同的编译器——所有这些选项都需要单独的dlib安装

如果您尝试使用 CMake 并且遇到一些错误 - 只需阅读 CMake 的输出,其中有很多详细信息。而且这种方式需要一定的CMake使用经验,可以获取文档here

所以回答你的主要问题 - 为什么要编译 8000 个函数 - 这是不考虑不同编译模式的代价。是的,这只是特定于 Visual Studio 的。在 Linux 机器上——你只需要安装一次

关于c++ - 为什么 Dlib 会编译 8000 多个函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43814073/

相关文章:

C++ 唯一元素的数量

python - 使用opencv和pyaudio从网络摄像头录制视频和音频

python - 为具有透明度的 PNG 设置背景颜色

iOS 将 dlib 添加到项目,链接器错误

c++ - 使用 cv_image 实现 dlib pyramid_up

python-3.x - Dlib(支持GPU)无法正常工作,不确定吗?

c++ - 在 boost::asio 中多次写入单个套接字

c++ - 如何将两个Python字典传递给map接收的C++函数

c++ - 错误: expect a ';' before curly bracket [closed]

c++ - 继承时找不到类名