(简体中文版)(VSCode阅读) (zh-CN)
注:本说明基于 Windows 10 22H2 (19045.3930) 和 Visual Studio 2022 17.5.5 制作。
- 在合适的地方使用
git clone "https://github.com/Microsoft/vcpkg.git"
克隆库。此操作将在目标目录下生成一个vcpkg
文件夹。 - 添加环境变量:
- 在Path中添加,如
D:\vcpkg
- 在Path中添加,如
- 打开
vcpkg
目录,并运行bootstrap-vcpkg.bat
。将会有如下输出:
D:\vcpkg>bootstrap-vcpkg.bat
Downloading https://github.com/microsoft/vcpkg-tool/releases/download/2024-02-07/vcpkg.exe -> D:\vcpkg\vcpkg.exe (using IE proxy: 127.0.0.1:5230)... done.
Validating signature... done.
vcpkg package management program version 2024-02-07-8a83681f921b10d86ae626fd833c253f4f8c355b
See LICENSE.txt for license information.
Telemetry
---------
vcpkg collects usage data in order to help us improve your experience.
The data collected by Microsoft is anonymous.
You can opt-out of telemetry by re-running the bootstrap-vcpkg script with -disableMetrics,
passing --disable-metrics to vcpkg on the command line,
or by setting the VCPKG_DISABLE_METRICS environment variable.
Read more about vcpkg telemetry at docs/about/privacy.md
D:\vcpkg>
Downloading https://github.com/microsoft/vcpkg-tool/releases/download/2024-02-07/vcpkg.exe -> D:\vcpkg\vcpkg.exe (using IE proxy: 127.0.0.1:5230)... done.
Validating signature... done.
vcpkg package management program version 2024-02-07-8a83681f921b10d86ae626fd833c253f4f8c355b
See LICENSE.txt for license information.
Telemetry
---------
vcpkg collects usage data in order to help us improve your experience.
The data collected by Microsoft is anonymous.
You can opt-out of telemetry by re-running the bootstrap-vcpkg script with -disableMetrics,
passing --disable-metrics to vcpkg on the command line,
or by setting the VCPKG_DISABLE_METRICS environment variable.
Read more about vcpkg telemetry at docs/about/privacy.md
D:\vcpkg>
或看到在根目录中出现新生成的vcpkg.exe
。
- 用Powershell打开
vcpkg
目录,输入vcpkg integrate install
,将vcpkg整合入Visual Studio。将会有如下输出:
PS D:\vcpkg> vcpkg integrate install
Applied user-wide integration for this vcpkg root.
CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=D:/vcpkg/scripts/buildsystems/vcpkg.cmake"
All MSBuild C++ projects can now #include any installed libraries. Linking will be handled automatically. Installing new libraries will make them instantly available.
PS D:\vcpkg>
Applied user-wide integration for this vcpkg root.
CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=D:/vcpkg/scripts/buildsystems/vcpkg.cmake"
All MSBuild C++ projects can now #include any installed libraries. Linking will be handled automatically. Installing new libraries will make them instantly available.
PS D:\vcpkg>
- 在Powershell中输入
vcpkg install protobuf protobuf:x64-windows
。将会有如下输出:
PS D:\vcpkg> vcpkg install protobuf protobuf:x64-windows
warning: In the September 2023 release, the default triplet for vcpkg libraries changed from x86-windows to the detected host triplet (x64-windows). For the old behavior, add --triplet x86-windows . To suppress this message, add --triplet x64-windows .
Computing installation plan...
The following packages will be built and installed:
protobuf:x64-windows@3.21.12#1
Detecting compiler hash for triplet x64-windows...
-- Automatically setting %HTTP(S)_PROXY% environment variables to "127.0.0.1:5230".
Restored 0 package(s) from C:\Users\Peter\AppData\Local\vcpkg\archives in 179 us. Use --debug to see more details.
Installing 1/1 protobuf:x64-windows@3.21.12#1...
Building protobuf:x64-windows@3.21.12#1...
-- Using cached protocolbuffers-protobuf-v3.21.12.tar.gz.
-- Cleaning sources at D:/vcpkg/buildtrees/protobuf/src/v3.21.12-fdb7676342.clean. Use --editable to skip cleaning for the packages you specify.
-- Extracting source D:/vcpkg/downloads/protocolbuffers-protobuf-v3.21.12.tar.gz
-- Applying patch fix-static-build.patch
-- Applying patch fix-default-proto-file-path.patch
-- Applying patch compile_options.patch
-- Using source at D:/vcpkg/buildtrees/protobuf/src/v3.21.12-fdb7676342.clean
-- Found external ninja('1.11.0').
-- Configuring x64-windows
-- Building x64-windows-dbg
-- Building x64-windows-rel
CMake Warning at scripts/cmake/vcpkg_copy_pdbs.cmake:44 (message):
Could not find a matching pdb file for:
D:/vcpkg/packages/protobuf_x64-windows/bin/libprotobuf-lite.dll
D:/vcpkg/packages/protobuf_x64-windows/bin/libprotobuf.dll
D:/vcpkg/packages/protobuf_x64-windows/bin/libprotoc.dll
D:/vcpkg/packages/protobuf_x64-windows/debug/bin/libprotobuf-lited.dll
D:/vcpkg/packages/protobuf_x64-windows/debug/bin/libprotobufd.dll
D:/vcpkg/packages/protobuf_x64-windows/debug/bin/libprotocd.dll
Call Stack (most recent call first):
ports/protobuf/portfile.cmake:123 (vcpkg_copy_pdbs)
scripts/ports.cmake:170 (include)
-- Fixing pkgconfig file: D:/vcpkg/packages/protobuf_x64-windows/lib/pkgconfig/protobuf-lite.pc
-- Fixing pkgconfig file: D:/vcpkg/packages/protobuf_x64-windows/lib/pkgconfig/protobuf.pc
-- Using cached msys2-mingw-w64-x86_64-pkgconf-1~2.1.0-1-any.pkg.tar.zst.
-- Using cached msys2-msys2-runtime-3.4.10-4-x86_64.pkg.tar.zst.
-- Using msys root at D:/vcpkg/downloads/tools/msys2/fdbea3694fb5c0d4
-- Fixing pkgconfig file: D:/vcpkg/packages/protobuf_x64-windows/debug/lib/pkgconfig/protobuf-lite.pc
-- Fixing pkgconfig file: D:/vcpkg/packages/protobuf_x64-windows/debug/lib/pkgconfig/protobuf.pc
-- Installing: D:/vcpkg/packages/protobuf_x64-windows/share/protobuf/copyright
-- Performing post-build validation
Stored binaries in 1 destinations in 1.4 s.
Elapsed time to handle protobuf:x64-windows: 6.1 min
protobuf:x64-windows package ABI: c30ce9286ddf61354781f5759c28b705188dcc28ae0aa6d1d09771e8869a6ae0
Total install time: 6.1 min
protobuf provides CMake targets:
# this is heuristically generated, and may not be correct
find_package(protobuf CONFIG REQUIRED)
target_link_libraries(main PRIVATE protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite)
protobuf provides pkg-config modules:
# Google's Data Interchange Format
protobuf-lite
# Google's Data Interchange Format
protobuf
PS D:\vcpkg>
warning: In the September 2023 release, the default triplet for vcpkg libraries changed from x86-windows to the detected host triplet (x64-windows). For the old behavior, add --triplet x86-windows . To suppress this message, add --triplet x64-windows .
Computing installation plan...
The following packages will be built and installed:
protobuf:x64-windows@3.21.12#1
Detecting compiler hash for triplet x64-windows...
-- Automatically setting %HTTP(S)_PROXY% environment variables to "127.0.0.1:5230".
Restored 0 package(s) from C:\Users\Peter\AppData\Local\vcpkg\archives in 179 us. Use --debug to see more details.
Installing 1/1 protobuf:x64-windows@3.21.12#1...
Building protobuf:x64-windows@3.21.12#1...
-- Using cached protocolbuffers-protobuf-v3.21.12.tar.gz.
-- Cleaning sources at D:/vcpkg/buildtrees/protobuf/src/v3.21.12-fdb7676342.clean. Use --editable to skip cleaning for the packages you specify.
-- Extracting source D:/vcpkg/downloads/protocolbuffers-protobuf-v3.21.12.tar.gz
-- Applying patch fix-static-build.patch
-- Applying patch fix-default-proto-file-path.patch
-- Applying patch compile_options.patch
-- Using source at D:/vcpkg/buildtrees/protobuf/src/v3.21.12-fdb7676342.clean
-- Found external ninja('1.11.0').
-- Configuring x64-windows
-- Building x64-windows-dbg
-- Building x64-windows-rel
CMake Warning at scripts/cmake/vcpkg_copy_pdbs.cmake:44 (message):
Could not find a matching pdb file for:
D:/vcpkg/packages/protobuf_x64-windows/bin/libprotobuf-lite.dll
D:/vcpkg/packages/protobuf_x64-windows/bin/libprotobuf.dll
D:/vcpkg/packages/protobuf_x64-windows/bin/libprotoc.dll
D:/vcpkg/packages/protobuf_x64-windows/debug/bin/libprotobuf-lited.dll
D:/vcpkg/packages/protobuf_x64-windows/debug/bin/libprotobufd.dll
D:/vcpkg/packages/protobuf_x64-windows/debug/bin/libprotocd.dll
Call Stack (most recent call first):
ports/protobuf/portfile.cmake:123 (vcpkg_copy_pdbs)
scripts/ports.cmake:170 (include)
-- Fixing pkgconfig file: D:/vcpkg/packages/protobuf_x64-windows/lib/pkgconfig/protobuf-lite.pc
-- Fixing pkgconfig file: D:/vcpkg/packages/protobuf_x64-windows/lib/pkgconfig/protobuf.pc
-- Using cached msys2-mingw-w64-x86_64-pkgconf-1~2.1.0-1-any.pkg.tar.zst.
-- Using cached msys2-msys2-runtime-3.4.10-4-x86_64.pkg.tar.zst.
-- Using msys root at D:/vcpkg/downloads/tools/msys2/fdbea3694fb5c0d4
-- Fixing pkgconfig file: D:/vcpkg/packages/protobuf_x64-windows/debug/lib/pkgconfig/protobuf-lite.pc
-- Fixing pkgconfig file: D:/vcpkg/packages/protobuf_x64-windows/debug/lib/pkgconfig/protobuf.pc
-- Installing: D:/vcpkg/packages/protobuf_x64-windows/share/protobuf/copyright
-- Performing post-build validation
Stored binaries in 1 destinations in 1.4 s.
Elapsed time to handle protobuf:x64-windows: 6.1 min
protobuf:x64-windows package ABI: c30ce9286ddf61354781f5759c28b705188dcc28ae0aa6d1d09771e8869a6ae0
Total install time: 6.1 min
protobuf provides CMake targets:
# this is heuristically generated, and may not be correct
find_package(protobuf CONFIG REQUIRED)
target_link_libraries(main PRIVATE protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite)
protobuf provides pkg-config modules:
# Google's Data Interchange Format
protobuf-lite
# Google's Data Interchange Format
protobuf
PS D:\vcpkg>
- 从https://think-async.com/Asio/Download.html下载asio,随后解压至合适的位置。
- 从https://cmake.org/download/下载并安装cmake。
⚠️ 注意选择◉ Add CMake to the system PATH for all users
而非⌾ Do not add CMake to the system PATH
- 从https://github.com/krpc/krpc/releases下载最新版本的kRPC client library并解压到合适的位置。
- 打开
./CMakeLists.txt
,在project(kRPC)
上一行或下一行新增asio和protobuf路径。完成后如下例:
...
set(ASIO_INCLUDE_DIR D:/asio-1.28.0/include)
list(APPEND CMAKE_PREFIX_PATH "D:/vcpkg/packages/protobuf_x64-windows")
project(kRPC)
...
-
(可选) 将构建模式从Debug改为Release。同样在
./CMakeLists.txt
中,将set(CMAKE_BUILD_TYPE "Debug")
改为set(CMAKE_BUILD_TYPE "Release")
即可。 -
从krpc目录下启动Powershell,运行
cmake .
指令。将会有如下输出,并可看到kRPC.sln
文件。
PS D:\Projects\krpc-cpp-0.5.2> cmake .
-- Building for: Visual Studio 17 2022
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
Compatibility with CMake < 3.5 will be removed from a future version of
CMake.
Update the VERSION argument value or use a ... suffix to tell
CMake that the project does not need compatibility with older versions.
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.19045.
-- The C compiler identification is MSVC 19.35.32217.1
-- The CXX compiler identification is MSVC 19.35.32217.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: D:/Microsoft Visual Studio/2022/VC/Tools/MSVC/14.35.32215/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:/Microsoft Visual Studio/2022/VC/Tools/MSVC/14.35.32215/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Protobuf: optimized;D:/vcpkg/installed/x64-windows/lib/libprotobuf.lib;debug;D:/vcpkg/installed/x64-windows/debug/lib/libprotobufd.lib (found suitable version "3.21.12", minimum required is "3.2")
-- Found Protobuf compiler D:/vcpkg/installed/x64-windows/tools/protobuf/protoc.exe
-- Configuring done (20.6s)
-- Generating done (0.1s)
-- Build files have been written to: D:/Projects/krpc-cpp-0.5.2
PS D:\Projects\krpc-cpp-0.5.2>
-- Building for: Visual Studio 17 2022
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
Compatibility with CMake < 3.5 will be removed from a future version of
CMake.
Update the VERSION argument value or use a ... suffix to tell
CMake that the project does not need compatibility with older versions.
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.19045.
-- The C compiler identification is MSVC 19.35.32217.1
-- The CXX compiler identification is MSVC 19.35.32217.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: D:/Microsoft Visual Studio/2022/VC/Tools/MSVC/14.35.32215/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:/Microsoft Visual Studio/2022/VC/Tools/MSVC/14.35.32215/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Protobuf: optimized;D:/vcpkg/installed/x64-windows/lib/libprotobuf.lib;debug;D:/vcpkg/installed/x64-windows/debug/lib/libprotobufd.lib (found suitable version "3.21.12", minimum required is "3.2")
-- Found Protobuf compiler D:/vcpkg/installed/x64-windows/tools/protobuf/protoc.exe
-- Configuring done (20.6s)
-- Generating done (0.1s)
-- Build files have been written to: D:/Projects/krpc-cpp-0.5.2
PS D:\Projects\krpc-cpp-0.5.2>
- 双击打开
kRPC.sln
,并点击"本地Windows调试器",启动生成。
稍作等待后应在"输出"面板中显示如下字样。
...
========== 生成: 3 成功,0 失败,0 最新,0 已跳过 ==========
...
如"成功"数目为"3",则请忽略"拒绝访问"的错误提示。
至此,构建结束。文件将生成在krpc目录下的./Release
或./Debug
文件夹中。