简介
在Windows上源码编译安装gRPC需要MSVC编译器、git、cmake、Perl、go、yasm、Ninja等工具,一些工具的安装可以使用choco(Windows上的包管理工具)来安装。
gRPC官方Windows安装说明:
- Install Visual Studio 2019 (Visual C++ compiler will be used).
- Install Git
- Install CMake
- Install Active State Perl (choco install activeperl) - required by boringssl
- Install Go (choco install golang) - required by boringssl
- Install yasm and add it to PATH (choco install yasm) - required by boringssl
- (Optional) Install Ninja (choco install ninja)
准备环境
- https://git-scm.com/上下载git
- https://cmake.org/download/上下载cmake,下载cmake-xxx-win64-x64.zip,解压并将cmake工具所在bin目录加入到系统环境变量Path。
- 安装choco
- 使用choco依次安装Perl、go、yasm、Ninja等工具
choco install activeperl
choco install golang
choco install yasm
choco install ninja
下载gRPC源码
- 下载代码
git clone -b RELEASE_TAG_HERE https://github.com/grpc/grpc.git
- 下载依赖
git submodule update --init
- 屏蔽警告(可选)
下载完毕后,打开文件./grpc/third_party/zlib/gzguts.h,修改如下:
#ifdef _WIN32
#inlcude <stddef.h>
#endif
改为
#ifdef _WIN32
#include <stddef.h>
#pragma warning(disable:4996)
#endif
VS2019 编译gRPC源码
生成grpc.sln
md .build
cd .build
cmake .. -G "Visual Studio 16 2019" #-DCMAKE_BUILD_TYPE=Release
编译
选择 :“ALL_BUILD”
安装
选择 :“INSTALL”
Example
- 预处理
_WIN32_WINNT=0x0A00 - 链接库
Ws2_32.lib
libprotobufd.lib
grpc.lib
grpc++.lib
gpr.lib
zlibd.lib
cares.lib
address_sorting.lib