安装visual studio需要安装哪些,可参考“参考3”。
官网也可以下编译好的,不过是release版本,如果要用debug版本,就要自己编译了。
主要是参照官网的教程,但是也会有一些异常情况,那我就记录下我的编译过程
这里我原先用的 visual-studio-profession-2017有问题,加上又过期,我就重新安装了community版本。
用的是下面这个来做命令行,由于我的已经打开,所以显示灰色
第一步编译protobuf,原先我是直接git clone 官网地址,然后编译一直出问题,后来我直接下载官方提供的https://github.com/google/protobuf/archive/v3.11.2.zip来编译
cd <protobuf-root-dir>
mkdir build
cd build
cmake -A x64 -DCMAKE_INSTALL_PREFIX=%cd%/install -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_MSVC_STATIC_RUNTIME=OFF ../cmake
cmake --build . --config Release -j 2
cmake --build . --config Release --target install
第二步就是编译ncnn,这里我也是直接git clone 官网最新的,也出了点问题,后来我就用tag:20230223版本来编译
cd <ncnn-root-dir>
mkdir -p build
cd build
cmake -A x64 -DCMAKE_INSTALL_PREFIX=%cd%/install -DProtobuf_INCLUDE_DIR=<protobuf-root-dir>/build/install/include -DProtobuf_LIBRARIES=<protobuf-root-dir>/build/install/lib/libprotobuf.lib -DProtobuf_PROTOC_EXECUTABLE=<protobuf-root-dir>/build/install/bin/protoc.exe -DNCNN_VULKAN=ON ..
cmake --build . --config Release -j 2
cmake --build . --config Release --target install
当然,我没用到DNCNN_VULKAN,所以设为OFF。
如果直接用第4行编译,编译可能会报:“OpenCV not found, examples won't be built”
所以我参考“参考1”博客,把设为-DNCNN_BUILD_EXAMPLES=OFF,同时参考“参考2”把-DOpenCV_DIR=D:/install-soft/opencv-3.4.11/opencv/build 设置为opencv的build这一层级。
接着还加了这个-DCMAKE_BUILD_TYPE=Debug编译debug版本,当然,protubuff也要编译对应的Debug版本库才可以,以下是编译的完整命令,主要是争对上面第4行修改。
cmake -A x64 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=%cd%/install -DProtobuf_INCLUDE_DIR=D:/xxx/2023coding/protobuf-3.11.2/protobuf-3.11.2/build3112/install/include -DProtobuf_LIBRARIES=D:/xxx/2023coding/protobuf-3.11.2/protobuf-3.11.2/build3112/Debug/libprotobufd.lib -DProtobuf_PROTOC_EXECUTABLE=D:/xxx/2023coding/protobuf-3.11.2/protobuf-3.11.2/build3112/Debug/protoc.exe -DNCNN_VULKAN=OFF -DNCNN_BUILD_EXAMPLES=OFF -DOpenCV_DIR=D:/install-soft/opencv-3.4.11/opencv/build ..
执行5,6行的时候,如果编译的是Debug版本,需要把Release改为Debug。
另外放一个我编译好的图片:
参考: