返回> 网站首页
ncnn编译
yoours2026-07-08 10:41:43
简介一边听听音乐,一边写写文章。
一、Vulkan
下载地址
https://sdk.lunarg.com/sdk/download/1.4.350.0/windows/vulkansdk-windows-X64-1.4.350.0.exe
二、 OpenCV
下载地址
https://github.com/opencv/opencv/releases/download/4.13.0/opencv-4.13.0-windows.exe
三、protobuf 源码
下载版本 protobuf-29.6.zip
https://github.com/protocolbuffers/protobuf/tree/v29.6
第三方代码下载
protobuf/third_party/
https://github.com/abseil/abseil-cpp/tree/4a2c63365eff8823a5221db86ef490e828306f9d
https://github.com/google/googletest/tree/4c9a3bb62bf3ba1f1010bf96f9c8ed767b363774
https://github.com/open-source-parsers/jsoncpp/tree/9059f5cad030ba11d37818847443a53918c327b1
编译
mkdir build-vs2022
cd build-vs2022
cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%cd%/install -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_MSVC_STATIC_RUNTIME=OFF ..
nmake
nmake install
四、ncnn
下载
https://github.com/Tencent/ncnn/tree/20260526
第三方下载
https://github.com/nihui/glslang/tree/fe88f421038e1bb0a25cd5c1b2dfe505db82d08f
编译
mkdir build-vs2022
cd build-vs2022
cmake -G"NMake Makefiles" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=%cd%/install \
-DNCNN_VULKAN=ON \
-DNCNN_BUILD_EXAMPLES=OFF \
-DNCNN_SIMPLEOCV=OFF \
-DOpenCV_DIR=E:/ncnn/opencv/build/x64/vc16 \
-Dprotobuf_DIR="E:/ncnn/protobuf-29.6/protobuf/build-vs2022/install/lib/cmake/protobuf" \
-Dabsl_DIR="E:/ncnn/protobuf-29.6/protobuf/build-vs2022/install/lib/cmake/absl" \
-Dutf8_range_DIR="E:/ncnn/protobuf-29.6/protobuf/build-vs2022/install/lib/cmake/utf8_range" \
-DOpenCV_DIR="E:/ncnn/opencv/build" \
-DCMAKE_CXX_FLAGS="/utf-8" ..
nmake
nmake install
五、测试示例
#include <iostream>
#include <ncnn/net.h>
#include <ncnn/gpu.h>
int main()
{
ncnn::create_gpu_instance();
// 查看可用 GPU
int gpu_count = ncnn::get_gpu_count();
std::cout << "Found " << gpu_count << " Vulkan device(s)." << std::endl;
if (gpu_count > 0)
{
int default_gpu = ncnn::get_default_gpu_index();
const ncnn::GpuInfo& info = ncnn::get_gpu_info(default_gpu);
printf(" 默认 GPU: %s\n", info.device_name());
}
return 0;
}