dlib+VS2019生成踩坑记录(Windows10环境)

简介: dlib+VS2019生成踩坑记录(Windows10环境)

dlib+VS2019生成记录

1. 准备工具

VS2019

请读者参考《VS2019安装和使用教程(超详细)》

cmake

下载地址

2018122814580746.png

分别对应解压版和硬盘安装版,解压版解压后要自行添加环境变量,安装版在安装步骤中可以勾选添加环境变量。

dlib库

下载地址

2018122814580746.png

下载后解压到自己指定的位置即可,在解压后的目录中找到dlib目录,在其子文件夹下的examples目录下新建两个目录“build”和“install”(作用后面会提及,也可以是任意位置的任意命名,但要保证自己找得到,在本文中建立在examples目录下,实际也可以建立在解压后的根目录下)

2018122814580746.png

2. 使用cmake生成VS2019的工程

1. GUI方式(推荐)

打开cmake-gui

2018122814580746.png

将Where is the source code设置成dlib库解压的位置,Where to build the binaries设置成新建的build文件夹的位置

2018122814580746.png

点击Configure,弹出对话框(注意这个对话框只有在首次使用时才会弹出,若未弹出,可以点击File->Delete Cache后在重新进行Configure),选择VS 16 2019,第二行生成器选择x64,点击Finish

2018122814580746.png

若出错且报错信息为:

CMake Error: Error: generator platform: x64
Does not match the platform used previously:
Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.

则说明之前使用过cmake进行过生成,需要将build目录中的生成文件全部删除后,重新进行Configure。

成功后将CMAKE_INSTALL_PERFIX改成新建的install目录,再次点击Configure

2018122814580746.png

再次成功后,在build文件夹中出现了一些生成的配置

2018122814580746.png2018122814580746.png

之后点击Generate

2018122814580746.png

2. 命令行方式

注意cmake对于VS2019的工程生成,指定64位生成并不能使用cmake -G "Visual Studio 16 2019 Win64" -T host = x64的命令进行生成。

2018122814580746.png

对于VS2019版本只提供-A选项的方式进行指定

cd D:\2022ProgramTest\dlib\dlib-19.22\dlib-19.22\examples\build
cmake -G "Visual Studio 16 2019" -A x64 ..

若报错

CMake Error: Error: generator platform: x64
Does not match the platform used previously:
Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.

解决方式同上一小节

3. 使用VS2019对工程进行生成

生成成功后会发现build目录中又生成了一些文件,包括一个.sln的解决方案

2018122814580746.png

双击dlib_project.sln或者在cmake-gui点击Open project

2018122814580746.png

进入VS2019后,右击ALL_BUILD,选择生成。注意:配置管理器要选择Release x64,配置生成正确的话是默认Debug x64

2018122814580746.png

生成成功之后再生成INSTALL

2018122814580746.png

INSTALL生成成功后会发现install目录中生成了一些新东西,include目录中是使用dlib所需包含的头文件,lib目录中包含了使用dlib所需的链接库。

2018122814580746.png

4. 测试

创建一个新项目,然后右键->属性

2018122814580746.png

将install文件夹中的include目录,包含到项目中的包含目录属性中

2018122814580746.png

将install文件夹中的lib目录,包含到项目中的库目录属性中

2018122814580746.png

在生成的install目录的lib目录下,有个.lib文件

2018122814580746.png

将这个lib文件加入链接器->输入->附加依赖项中,将文件名复制进去即可

2018122814580746.png

新建源文件进行生成运行测试

源码为官方例程

// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
/*
    This is an example illustrating the use of the perspective_window tool
    in the dlib C++ Library.  It is a simple tool for displaying 3D point
    clouds on the screen.
*/
#include <dlib/gui_widgets.h>
#include <dlib/image_transforms.h>
#include <cmath>
using namespace dlib;
using namespace std;
// ----------------------------------------------------------------------------------------
int main()
{
    // Let's make a point cloud that looks like a 3D spiral.
    std::vector<perspective_window::overlay_dot> points;
    dlib::rand rnd;
    for (double i = 0; i < 20; i += 0.001)
    {
        // Get a point on a spiral
        dlib::vector<double> val(sin(i), cos(i), i / 4);
        // Now add some random noise to it
        dlib::vector<double> temp(rnd.get_random_gaussian(),
            rnd.get_random_gaussian(),
            rnd.get_random_gaussian());
        val += temp / 20;
        // Pick a color based on how far we are along the spiral
        rgb_pixel color = colormap_jet(i, 0, 20);
        // And add the point to the list of points we will display
        points.push_back(perspective_window::overlay_dot(val, color));
    }
    // Now finally display the point cloud.
    perspective_window win;
    win.set_title("perspective_window 3D point cloud");
    win.add_overlay(points);
    win.wait_until_closed();
}
//  ----------------------------------------------------------------------------

效果如下:

2018122814580746.png

3D图画可用鼠标拖拽

至此测试成功

相关文章
|
3月前
|
XML Ubuntu Linux
部署08---扩展-Win10配置WSL(Ubuntu)环境,WSL系统是什么意思,是Windows系统上的一个子系统, xml的一大特点是直链系统,直接链接你的CPU,硬盘和内存,如何用 WSL部署
部署08---扩展-Win10配置WSL(Ubuntu)环境,WSL系统是什么意思,是Windows系统上的一个子系统, xml的一大特点是直链系统,直接链接你的CPU,硬盘和内存,如何用 WSL部署
|
2月前
|
Linux C++ Windows
【Azure 应用服务】Azure App Service(Windows)环境中如何让.NET应用调用SAP NetWeaver RFC函数
【Azure 应用服务】Azure App Service(Windows)环境中如何让.NET应用调用SAP NetWeaver RFC函数
【Azure 应用服务】Azure App Service(Windows)环境中如何让.NET应用调用SAP NetWeaver RFC函数
|
2月前
|
传感器 网络协议 物联网
手把手教你在 Windows 环境中搭建 MQTT 服务器
手把手教你在 Windows 环境中搭建 MQTT 服务器
143 0
|
22天前
|
SQL JavaScript 数据库
sqlite在Windows环境下安装、使用、node.js连接
sqlite在Windows环境下安装、使用、node.js连接
|
2月前
|
Java 应用服务中间件 Windows
【App Service for Windows】为 App Service 配置自定义 Tomcat 环境
【App Service for Windows】为 App Service 配置自定义 Tomcat 环境
|
2月前
|
并行计算 TensorFlow 算法框架/工具
Windows11+CUDA12.0+RTX4090如何配置安装Tensorflow2-GPU环境?
本文介绍了如何在Windows 11操作系统上,配合CUDA 12.0和RTX4090显卡,通过创建conda环境、安装特定版本的CUDA、cuDNN和TensorFlow 2.10来配置TensorFlow GPU环境,并提供了解决可能遇到的cudnn库文件找不到错误的具体步骤。
200 3
|
2月前
|
Windows
Windows 10找不到恢复环境
Windows 10找不到恢复环境
19 0
|
2月前
|
Java 应用服务中间件 Windows
【Azure 应用服务】App Service for Windows 环境中为Tomcat自定义4xx/5xx页面
【Azure 应用服务】App Service for Windows 环境中为Tomcat自定义4xx/5xx页面
|
2月前
|
Windows
【Azure 环境】在Windows环境中抓取网络包(netsh trace)后,如何转换为Wireshark格式以便进行分析
【Azure 环境】在Windows环境中抓取网络包(netsh trace)后,如何转换为Wireshark格式以便进行分析
|
2月前
|
存储 安全 网络安全
【Azure 环境】使用Azure中的App Service部署Web应用,以Windows为主机系统是否可以启动防病毒,防恶意软件服务呢(Microsoft Antimalware)?
【Azure 环境】使用Azure中的App Service部署Web应用,以Windows为主机系统是否可以启动防病毒,防恶意软件服务呢(Microsoft Antimalware)?
下一篇
无影云桌面