未验证 提交 f9180330 编写于 作者: H He Yang 提交者: GitHub

update how-to-build.md and delete obsolete tutorials in docs (#4660)

上级 bd15e325
# Compile with Visual Studio
[TOC]
## Prepare
Community Edition version of Visual Studio 2015 / 2017 / 2019 / **2022** Preview, using dynamic CRT runtime
CMake, version >= 3.17 recommended
## Compiling
### minimal compilation
https://github.com/Tencent/ncnn.git
#### command prompt version
```batch
mkdir build-vs2022
cd build-vs2022
cmake -G "Visual Studio 17 2022" -A x64 ..
cmake --build . --config Release
cmake --install . --config Release
cmake --build . --config Debug
cmake --install . --config Debug
```
It will be installed in build-vs2022/install, and the debug version of the library will have a `d` suffix.
#### x64 native tools command prompt version (no x64 for VS2022)
ncnn
protobuf defines parameters with reference to the following
```batch
mkdir build-vs2022
cd build-vs2022
cmake ..
cmake --build .
cmake --install . --config Debug
// The default build generates the Debug version; the default install installs the Release version. Refer to the command prompt version
```
### Compile and install the ncnn library with Vulkan support
#### Device and Vulkan preparation
Confirm that the device supports Vulkan, and install the graphics driver.
Download and install the Vulkan SDK : https://vulkan.lunarg.com/sdk/home
Along with submodules, get the source code:
- The "ncnn-YYYYMMDD-full-source.zip" download can be found at http://github.com/Tencent/ncnn/releases
- Or get the latest version with git:
```batch
git clone https://github.com/tencent/ncnn
git submodule update --init
```
#### Compile and install ncnn
```batch
mkdir build-vs2022
cd build-vs2022
cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_INSTALL_PREFIX="%cd%/install" -DNCNN_VULKAN=ON
cmake --build . --config Release
cmake --install . --config Release
cmake --build . --config Debug
cmake --install . --config Debug
```
### Compile and install ncnn library and model conversion tool
- This step is used to compile the model conversion tool, which can be skipped and converted directly using the https://convertmodel.com tool
- The following command lines all use **x64 Native Tools Command Prompt for VS 2022**
*Note: If it is done in cmd / PowerShell, it needs to be modified:*
- `-G"NMake Makefile"` Change to a suitable Generator such as `-G "Visual Studio 17 2022" -A x64`
- `nmake` change to `cmake --build . --config Release`, or open `.sln` manually trigger the build of `protobuf` / `ncnn` items
- `nmake install` change to `cmake --install . --config Release`or open `.sln` manually trigger the build of `INSTALL` items
#### Compile and install protobuf
Tools for generating caffe2ncnn and onnx2ncnn
https://github.com/google/protobuf/archive/v3.4.0.zip
Download it to C:/Users/{{user-name}}/source and unzipped it
```batch
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 ../cmake
nmake
nmake install
```
protobuf will be installed in build-vs2022/install
#### Compile and install ncnn
https://github.com/Tencent/ncnn.git
The protobuf path in the cmake command should be modified accordingly to its own
```batch
mkdir build-vs2022
cd build-vs2022
cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="%cd%/install" ^
-DProtobuf_INCLUDE_DIR=C:/Users/{{user-name}}/source/protobuf-3.4.0/build-vs2022/install/include ^
-DProtobuf_LIBRARIES=C:/Users/{{user-name}}/source/protobuf-3.4.0/build-vs2022/install/lib/libprotobuf.lib ^
-DProtobuf_PROTOC_EXECUTABLE=C:/Users/{{user-name}}/source/protobuf-3.4.0/build-vs2022/install/bin/protoc.exe ..
nmake
nmake install
```
ncnn will be installed in build-vs2022/install
The ncnn conversion tool is in build-vs2022/tools
#### mlir2ncnn
see [build-mlir2ncnn](build-mlir2ncnn.md)
## Use the compiled ncnn library
Write in CMakeLists
```cmake
set(ncnn_DIR "C:/Users/{{user-name}}/source/ncnn/build-vs2022/install/lib/cmake/ncnn" CACHE PATH "Directory containing ncnnConfig.cmake")
find_package(ncnn REQUIRED)
target_link_libraries(my_target ncnn)
```
Learn more about [use-ncnn-with-own-project](https://github.com/Tencent/ncnn/wiki/use-ncnn-with-own-project)
# 用 Visual Studio 编译
[TOC]
## 预先准备
Visual Studio 2015 / 2017 / 2019 / 2022 Preview 的 Community Edition 版本, 使用动态的 CRT 运行库
CMake, 推荐 >= 3.17 的版本
## 开始编译
### 最简编译
https://github.com/Tencent/ncnn.git
#### 命令提示符版本
```batch
mkdir build-vs2019
cd build-vs2019
cmake -G "Visual Studio 16 2019" -A x64 ..
cmake --build . --config Release
cmake --install . --config Release
cmake --build . --config Debug
cmake --install . --config Debug
```
会安装在 build-vs2019/install 里头,debug 版本的库会带有 `d` 后缀。
#### x64 本机工具命令提示符 版本 (VS2022无X64)
ncnn
protobuf参照后文定义参数
```batch
mkdir build-vs2019
cd build-vs2019
cmake ..
cmake --build .
cmake --install . --config Debug
//默认build生成Debug版本;默认install安装Relase版本。 参照命令提示符版本
```
### 编译安装带 Vulkan 支持的 ncnn 库
#### 设备和 Vulkan 准备
确认设备支持 Vulkan, 安装显卡驱动。
下载和安装 Vulkan SDK: https://vulkan.lunarg.com/sdk/home
连同子模块一起,获取源码:
- 可从 http://github.com/Tencent/ncnn/releases 找到 "ncnn-YYYYMMDD-full-source.zip" 下载
- 或用 git 获取最新版本:
```batch
git clone https://github.com/tencent/ncnn
git submodule update --init
```
#### 编译安装 ncnn
```batch
mkdir build-vs2019
cd build-vs2019
cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_INSTALL_PREFIX="%cd%/install" -DNCNN_VULKAN=ON
cmake --build . --config Release
cmake --install . --config Release
cmake --build . --config Debug
cmake --install . --config Debug
```
### 编译安装 ncnn 库和模型转换工具
- 此步骤用于编译模型转换工具,可跳过,直接使用 https://convertmodel.com 工具转换
- 以下命令行均使用 **适用于 VS 2019 的 x64 本机工具命令提示**
*注:若在 cmd / PowerShell 进行,需修改:*
- `-G"NMake Makefile"` 改为合适的 Generator 如 `-G "Visual Studio 16 2019" -A x64`
- `nmake` 改为 `cmake --build . --config Release`, 或打开 `.sln` 手动触发 `protobuf` / `ncnn` 项的构建
- `nmake install` 改为 `cmake --install . --config Release`,或打开 `.sln` 手动触发 `INSTALL` 项的构建
#### 编译安装 protobuf
用于生成 caffe2ncnn 和 onnx2ncnn 工具
https://github.com/google/protobuf/archive/v3.4.0.zip
我下载到 C:/Users/shuiz/source 解压缩
```batch
mkdir build-vs2019
cd build-vs2019
cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="%cd%/install" ^
-Dprotobuf_BUILD_TESTS=OFF ^
-Dprotobuf_MSVC_STATIC_RUNTIME=OFF ../cmake
nmake
nmake install
```
protobuf 会安装在 build-vs2019/install 里头
#### 编译安装 ncnn
https://github.com/Tencent/ncnn.git
cmake 命令中的 protobuf 路径要相应修改成自己的
```batch
mkdir build-vs2019
cd build-vs2019
cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="%cd%/install" ^
-DProtobuf_INCLUDE_DIR=C:/Users/shuiz/source/protobuf-3.4.0/build-vs2019/install/include ^
-DProtobuf_LIBRARIES=C:/Users/shuiz/source/protobuf-3.4.0/build-vs2019/install/lib/libprotobuf.lib ^
-DProtobuf_PROTOC_EXECUTABLE=C:/Users/shuiz/source/protobuf-3.4.0/build-vs2019/install/bin/protoc.exe ..
nmake
nmake install
```
ncnn 会安装在 build-vs2019/install 里头
ncnn 转换工具在 build-vs2019/tools 里头
#### mlir2ncnn
[build-mlir2ncnn](build-mlir2ncnn.md)
## 使用编译好的 ncnn 库
CMakeLists 里写
```cmake
set(ncnn_DIR "C:/Users/shuiz/source/ncnn/build-vs2019/install/lib/cmake/ncnn" CACHE PATH "包含 ncnnConfig.cmake 的目录")
find_package(ncnn REQUIRED)
target_link_libraries(my_target ncnn)
```
进一步了解 [use-ncnn-with-own-project](../how-to-use-and-FAQ/use-ncnn-with-own-project.md)
......@@ -147,9 +147,9 @@ Build ncnn library (replace <protobuf-root-dir> with a proper path):
```shell
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 ..
mkdir -p protobuf_build
cd protobuf_build
cmake -A x64 -DCMAKE_INSTALL_PREFIX=%cd%/install -DProtobuf_INCLUDE_DIR=<protobuf-root-dir>/protobuf_build/install/include -DProtobuf_LIBRARIES=<protobuf-root-dir>/protobuf_build/install/lib/libprotobuf.lib -DProtobuf_PROTOC_EXECUTABLE=<protobuf-root-dir>/protobuf_build/install/bin/protoc.exe -DNCNN_VULKAN=ON ..
cmake --build . --config Release -j 2
cmake --build . --config Release --target install
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册