ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

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

2022-01-04 22:59:40  阅读:252  来源: 互联网

标签:cmake VS2019 Windows10 生成 build 目录 dlib


dlib+VS2019生成记录

1. 准备工具

VS2019
请读者参考《VS2019安装和使用教程(超详细)》
cmake
下载地址
在这里插入图片描述
分别对应解压版和硬盘安装版,解压版解压后要自行添加环境变量,安装版在安装步骤中可以勾选添加环境变量。
dlib库
下载地址
在这里插入图片描述
下载后解压到自己指定的位置即可,在解压后的目录中找到dlib目录,在其子文件夹下的examples目录下新建两个目录“build”和“install”(作用后面会提及,也可以是任意位置的任意命名,但要保证自己找得到,在本文中建立在examples目录下,实际也可以建立在解压后的根目录下)在这里插入图片描述

2. 使用cmake生成VS2019的工程

1. GUI方式(推荐)

打开cmake-gui
在这里插入图片描述

将Where is the source code设置成dlib库解压的位置,Where to build the binaries设置成新建的build文件夹的位置
在这里插入图片描述
点击Configure,弹出对话框(注意这个对话框只有在首次使用时才会弹出,若未弹出,可以点击File->Delete Cache后在重新进行Configure),选择VS 16 2019,第二行生成器选择x64,点击Finish
在这里插入图片描述
若出错且报错信息为:

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
在这里插入图片描述
再次成功后,在build文件夹中出现了一些生成的配置
在这里插入图片描述
在这里插入图片描述
之后点击Generate
在这里插入图片描述

2. 命令行方式

注意cmake对于VS2019的工程生成,指定64位生成并不能使用cmake -G "Visual Studio 16 2019 Win64" -T host = x64的命令进行生成。
在这里插入图片描述
对于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的解决方案
在这里插入图片描述
双击dlib_project.sln或者在cmake-gui点击Open project
在这里插入图片描述
进入VS2019后,右击ALL_BUILD,选择生成。注意:配置管理器要选择Release x64,配置生成正确的话是默认Debug x64
在这里插入图片描述
生成成功之后再生成INSTALL
在这里插入图片描述
INSTALL生成成功后会发现install目录中生成了一些新东西,include目录中是使用dlib所需包含的头文件,lib目录中包含了使用dlib所需的链接库。
在这里插入图片描述

4. 测试

创建一个新项目,然后右键->属性
在这里插入图片描述
将install文件夹中的include目录,包含到项目中的包含目录属性中
在这里插入图片描述
将install文件夹中的lib目录,包含到项目中的库目录属性中
在这里插入图片描述
在生成的install目录的lib目录下,有个.lib文件
在这里插入图片描述
将这个lib文件加入链接器->输入->附加依赖项中,将文件名复制进去即可
在这里插入图片描述
新建源文件进行生成运行测试
源码为官方例程

// 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();
}

//  ----------------------------------------------------------------------------

效果如下:
在这里插入图片描述
3D图画可用鼠标拖拽
至此测试成功

标签:cmake,VS2019,Windows10,生成,build,目录,dlib
来源: https://blog.csdn.net/qq_38853759/article/details/122311558

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有