vcpkg.exe
Vcpkg 可帮助您在 Windows、 Linux 和 MacOS 上管理 C 和 C++ 库 。
避免 编译一个库需要安装各种工具,从而避免 Windows下复杂的编译步骤 。
安装编译后,在 C:\src\vcpkg\vcpkg-2021.05.12\installed
目录下包含:
x86-windows-static
x64-windows-static
一. 常用命令
1. 搜索可被编译的包
C:>vcpkg.exe search | findstr "protobuf"
2. 安装库语法
C:>vcpkg install [packagesname]:triplet
- 注意
- 不指定
triplet
(可以认为是架构),默认安装的是x86,大概率还是动态库版本 - 编译安装库。编译好后存放在
vcpkg
的installed
下的x64-windows-static
目录 debug
为MTd
Relase
下为MT
debug
工程需要使用x64-windows-static\debug
目录下的库.并把工程的Runtime Library
修改为MTd
.Release
做相似的修改 .
- 不指定
3. 查看支持的架构
PS E:\dev\vcpkg> ./vcpkg.exe help triplet
Available architecture triplets
VCPKG built-in triplets:
arm-uwp
arm64-windows
x64-linux
x64-osx
x64-uwp
x64-windows-static
x64-windows
x86-windows
......
4. 查看已安装的库
C:\src\vcpkg\vcpkg-2021.05.12>vcpkg list
protobuf:x64-windows-static 3.15.8#1 Protocol Buffers - Google's data interchange format
protobuf:x86-windows-static 3.15.8#1 Protocol Buffers - Google's data interchange format
5. 更新包和依赖
C:>./vcpkg update
6. 更新vcpkg
C:>vcpkg git pull
二. 使用案例
1. 安装 x64 静态库版本的 protobuf
C:\src\vcpkg\vcpkg-2021.05.12>vcpkg install protobuf:x64-windows-static
- 安装后在目录
C:\src\vcpkg\vcpkg-2021.05.12\installed\x64-windows-static
下子目录结构debug
包含调试版本的静态库include
包含头文件lib
包含release
的静态库share
tools
对应的二进制文件.protoc.exe
2. 安装 x86 静态库版本的 protobuf
C:\src\vcpkg\vcpkg-2021.05.12>vcpkg install protobuf:x86-windows-static
- 安装后在目录
C:\src\vcpkg\vcpkg-2021.05.12\installed\x86-windows-static
。
3. 移除库
./vcpkg.exe remove jsoncpp:x64-windows-static
4. 导出包
C:>./vcpkg.exe export jsoncpp:x64-windows-static --zip
三. 根据 *.proto 生成 *.h 和 *.cc
protoc -I . --cpp_out=. addressbook.proto