VS2017为何编译Dlib DNN系列代码hangup
Dlib 19.7 + VS2017
http://dlib.net/faq.html#Whyisdlibslow
Why can't I use the DNN module with Visual Studio?
You can, but you need to use Visual Studio 2015 Update 3 or newer since prior versions had bad C++11 support. To make this as confusing as possible, Microsoft has released multiple different versions of "Visual Studio 2015 Update 3". As of October 2016, the version available from the Microsoft web page has good enough C++11 support to compile the DNN tools in dlib. So make sure you have a version no older than October 2016.
However, as of this writing, the newest version of Visual Studio is Visual Studio 2017, which has WORSE C++11 support that Visual Studio 2015. In particular, if you try to use the DNN tooling in Visual Studio 2017 the compiler will just hang. So use Visual Studio 2015.
It should also be noted that not even Visual Studio 2015 has perfect C++11 support. Specifically, the larger and more complex imagenet and metric learning training examples don't compile in Visual Studio 2015.
编译结果
PS D:\work\book\new Book\MachineLearn(DeepLearn)\OpenSourceFramework\dlib\dlib-master\examples\build> cmake -G "Visual Studio 14 2015 Win64" .. -- The C compiler identification is MSVC 19.0.24215.1 -- The CXX compiler identification is MSVC 19.0.24215.1 -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Looking for sys/types.h -- Looking for sys/types.h - found -- Looking for stdint.h -- Looking for stdint.h - found -- Looking for stddef.h -- Looking for stddef.h - found -- Check size of void* -- Check size of void* - done -- Enabling SSE2 instructions -- Searching for BLAS and LAPACK -- Searching for BLAS and LAPACK -- Looking for pthread.h -- Looking for pthread.h - not found -- Found Threads: TRUE -- A library with BLAS API not found. Please specify library location. -- LAPACK requires BLAS -- Found CUDA: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0 (found suitable version "9.0", minimum required is "7.5") -- Looking for cuDNN install... -- Found cuDNN: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0/lib/x64/cudnn.lib -- Building a CUDA test project to see if your compiler is compatible with CUDA... -- Checking if you have the right version of cuDNN installed. -- Enabling CUDA support for dlib. DLIB WILL USE CUDA -- C++11 activated. OpenCV not found, so we won't build the webcam_face_pose_ex example. -- Configuring done -- Generating done -- Build files have been written to: D:/work/book/new Book/MachineLearn(DeepLearn)/OpenSourceFramework/dlib/dlib-master/examples/build
VS2015对C++11 的SFINAE 支持比较好。其他版本暂时没有支持
https://github.com/davisking/dlib/issues/946 最新版本 把递归函数改成inline 放入头文件,能节省 很多 RAM 占用率。 [20171201 UTC] davisking commented 5 days ago Someone discovered that disabling inlining of recursive functions in visual studio 2015 significantly improves the RAM usage and build times of the DNN examples. I pushed this change to github last night. So at least you can compile all the DNN examples with visual studio 2015 in reasonable time. VC2017 still has additional C++11 bugs that prevent it from working though.
在VS 2015 Update 3 中对SFINAE表达式的改进
https://blogs.msdn.microsoft.com/c/2016/06/16/在vs-2015-update-3-中对sfinae表达式的改进/
什么是SFINAE?
提醒一下,SFINAE是‘Substitution Failure Is Not An Error’的缩写。其理念是当编译器尝试在重载解析时去特化一个函数模板,即使特化失败,只要还有其他的有效对象就可以。C++11介绍了诸如像decltype和constexpr的功能,并且在模板参数推导和替换过程中有表达式更为普遍。C++标准委员会阐明了C++11中SFINAE表达式的规则。
=============20171204
https://github.com/davisking/dlib/issues/946
davisking commented 3 days ago Sweet. I just tried it with the newest version of VS2017 and they all work now. Also, if you give -T host=x64 to cmake when generating the project it will use the 64bit toolchain. That allowed me to compile the examples that would otherwise cause VS to run out of RAM and crash. So at this point it looks like the newest VS2017 works correctly for everything!
嗯,赶紧删了VS2015
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)