grpc安装(windows or Linux)
下载源码
这里使用 gRPC 最新版本源代码进行编译和安装,版本号为 v1.50.0, 以下为安装步骤:
一、使用Git克隆gRPC到本地
在终端中打开某一文件夹,建议新建一个单独存放 gRPC 源代码的文件夹,输入:
git clone -b v1.50.0 https://github.com/grpc/grpc
二、安装依赖
gRPC 编译时需要安装一些第三方依赖,使用命令:
git submodule update --init
将会自动安装,但由于国内网络或者其他原因导致下载速度非常慢,所以我们需要手动修改"grpc/.gitmodules"将第依赖安装源更换为国内 gitee 同步仓库,下载效率将会大大改善,"grpc/.gitmodules"文件如下:
[submodule "third_party/abseil-cpp"]path = third_party/abseil-cppurl = https://gitee.com/suuair/abseil-cpp.git
[submodule "third_party/benchmark"]path = third_party/benchmarkurl = https://gitee.com/chahan/benchmark.git
[submodule "third_party/bloaty"]path = third_party/bloatyurl = https://gitee.com/GgBoy_ssz/bloaty.git
[submodule "third_party/boringssl-with-bazel"]path = third_party/boringssl-with-bazelurl = https://gitee.com/GgBoy_ssz/boringssl.git
[submodule "third_party/cares/cares"]path = third_party/cares/caresurl = https://gitee.com/RicLee/c-ares.git
[submodule "third_party/envoy-api"]path = third_party/envoy-apiurl = https://gitee.com/RicLee/data-plane-api.git
[submodule "third_party/googleapis"]path = third_party/googleapisurl = https://gitee.com/GgBoy_ssz/googleapis.git
[submodule "third_party/googletest"]path = third_party/googletesturl = https://gitee.com/bosspoi/googletest.git
[submodule "third_party/libuv"]path = third_party/libuvurl = https://gitee.com/RicLee/libuv.git
[submodule "third_party/opencensus-proto"]path = third_party/opencensus-protourl = https://gitee.com/RicLee/opencensus-proto.git
[submodule "third_party/opentelemetry"]path = third_party/opentelemetryurl = https://gitee.com/EBServerStudy/opentelemetry-proto.git
[submodule "third_party/protobuf"]path = third_party/protobufurl = https://gitee.com/EBServerStudy/protobuf.git
[submodule "third_party/protoc-gen-validate"]path = third_party/protoc-gen-validateurl = https://gitee.com/arzhe/protoc-gen-validate.git
[submodule "third_party/re2"]path = third_party/re2url = https://gitee.com/GgBoy_ssz/re2.git
[submodule "third_party/xds"]path = third_party/xdsurl = https://gitee.com/EBServerStudy/xds.git
[submodule "third_party/zlib"]path = third_party/zliburl = https://gitee.com/RicLee/zlib.git# When using CMake to build, the zlib submodule ends up with a# generated file that makes Git consider the submodule dirty. This# state can be ignored for day-to-day development on gRPC.ignore = dirty
打开 grpc/.gitmodules 文件,更新为上述内容
执行命令 git submodule sync
同步 URL
git submodule sync
执行命令 git submodule update --init
下载第三方依赖
git submodule update --init
下载完成后即可开始编译
Windows
环境: MinGW + CMake
如果gcc版本超过11,需要对部分源码进行修改
在
#include<limits>
windows下还需要修改<your_grpc_path>\third_party\re2\util\pcre.h中的503行 :
mutable int32_t hit_limit_;
# 修改为:
mutable int hit_limit_
然后即可执行以下操作开始编译:
mkdir build
cd build
cmake .. -G "MinGW Makefiles"
mingw-make.exe -j8
之后以管理员身份打开 cmd 或者 powershell, cd 到grpc/build目录,执行mingw-make install -j8
即可将grpc安装到program files (x64)
目录
mingw-make install -j8
Linux
Linux下同样需要在
#include<limits>
然后开始编译
mkdir build
cd build
cmake ..
make -j8
sudo make install
验证
官方提供了一套测试样例,位于 grpc/examples/目录下,找到 cpp/helloworld 文件夹,这里存放我们需要测试的程序.
同样cmake + make后,运行server程序和client程序即可.
注: 需要有protobuff环境
大部分内容来自该作者,链接:https://blog.csdn.net/qq_37434641/article/details/127561281