1. 准备阶段 - 创建构建目录
考虑到make之后的文件多,看着乱,所以创建构建目录
bash
# 在项目根目录下
mkdir build
cd build- 创建独立的
build目录进行"out-of-source"构建,保持源码目录清洁 - 所有编译生成的文件都集中在build目录中
2. 配置阶段 - 生成构建系统
bash
# 在build目录中执行
cmake ..执行过程大致如下:
bash
(base) PS D:\0.Project\0.VS\Py_project\ONNX\CNN_CIFAR-10\build> cmake ..
-- Building for: Visual Studio 17 2022
-- The C compiler identification is MSVC 19.34.31948.0
-- The CXX compiler identification is MSVC 19.34.31948.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: D:/visual intall/VC/Tools/MSVC/14.34.31933/bin/HostX64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: D:/visual intall/VC/Tools/MSVC/14.34.31933/bin/HostX64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (3.7s)
-- Generating done (0.0s)
-- Build files have been written to: D:/0.Project/0.VS/Py_project/ONNX/CNN_CIFAR-10/build- CMake读取根目录的
CMakeLists.txt - 检测系统编译器和工具链
- 配置ONNX Runtime路径:
D:/0.Project/0.VS/Py_project/ONNX/onnxruntime-win-x64-gpu-1.23.0 - 生成对应的构建文件(Makefile或Visual Studio项目)
3. 构建阶段 - 编译项目
bash
# 在build目录中执行
cmake --build . --config Release执行过程大致如下:
bash
(base) PS D:\0.Project\0.VS\Py_project\ONNX\CNN_CIFAR-10\build> cmake --build . --config Release
适用于 .NET Framework MSBuild 版本 17.11.9+a69bbaaf5
Checking Build System
Building Custom Rule D:/0.Project/0.VS/Py_project/ONNX/CNN_CIFAR-10/CMakeLists.txt
main.cpp
cifar10_reader.cpp
正在生成代码...
CIFAR10Classifier.vcxproj -> D:\0.Project\0.VS\Py_project\ONNX\CNN_CIFAR-10\build\Release\CIFAR10Classifier.exe
Building Custom Rule D:/0.Project/0.VS/Py_project/ONNX/CNN_CIFAR-10/CMakeLists.txt
(base) PS D:\0.Project\0.VS\Py_project\ONNX\CNN_CIFAR-10\build>--build .:在当前目录(build)执行构建--config Release:指定Release配置(优化编译)- 编译两个源文件:
main.cpp和cifar10_reader.cpp - 链接ONNX Runtime库:
onnxruntime.lib - 自动执行POST_BUILD命令:复制DLL文件到输出目录
5. 运行阶段 - 执行程序
bash
# 在build目录中执行
.\CIFAR10Classifier.exe