环境信息:
1、操作系统:centos7.4
2、g++版本:4.8.5
grpc v1.29.1 版本 源码下载:(因为国内现在访问github速度很慢,这里用了代理镜像)
git clone -b v1.29.1 https://hub.xn--gzu630h.xn--kpry57d/grpc/grpc.git
配套三方依赖库下载:
cd grpc
git submodule update --init
具体依赖的三方库信息可以通过以下方式查看:
cd grpc
vim .gitmodules
[submodule "third_party/zlib"]
path = third_party/zlib
url = https://hub.xn--gzu630h.xn--kpry57d/madler/zlib
# 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
[submodule "third_party/protobuf"]
path = third_party/protobuf
url = https://hub.xn--gzu630h.xn--kpry57d/google/protobuf.git
branch = 3.0.x
[submodule "third_party/gflags"]
path = third_party/gflags
url = https://hub.xn--gzu630h.xn--kpry57d/gflags/gflags.git
[submodule "third_party/googletest"]
path = third_party/googletest
url = https://hub.xn--gzu630h.xn--kpry57d/google/googletest.git
[submodule "third_party/benchmark"]
path = third_party/benchmark
url = https://hub.xn--gzu630h.xn--kpry57d/google/benchmark
[submodule "third_party/boringssl-with-bazel"]
path = third_party/boringssl-with-bazel
url = https://hub.xn--gzu630h.xn--kpry57d/google/boringssl.git
[submodule "third_party/cares/cares"]
path = third_party/cares/cares
url = https://hub.xn--gzu630h.xn--kpry57d/c-ares/c-ares.git
branch = cares-1_12_0
[submodule "third_party/bloaty"]
path = third_party/bloaty
url = https://hub.xn--gzu630h.xn--kpry57d/google/bloaty.git
[submodule "third_party/abseil-cpp"]
path = third_party/abseil-cpp
url = https://hub.xn--gzu630h.xn--kpry57d/abseil/abseil-cpp.git
branch = lts_2020_02_25
[submodule "third_party/envoy-api"]
path = third_party/envoy-api
url = https://hub.xn--gzu630h.xn--kpry57d/envoyproxy/data-plane-api.git
[submodule "third_party/googleapis"]
path = third_party/googleapis
url = https://hub.xn--gzu630h.xn--kpry57d/googleapis/googleapis.git
[submodule "third_party/protoc-gen-validate"]
path = third_party/protoc-gen-validate
url = https://hub.xn--gzu630h.xn--kpry57d/envoyproxy/protoc-gen-validate.git
[submodule "third_party/udpa"]
path = third_party/udpa
url = https://hub.xn--gzu630h.xn--kpry57d/cncf/udpa.git
[submodule "third_party/libuv"]
path = third_party/libuv
url = https://hub.xn--gzu630h.xn--kpry57d/libuv/libuv.git
注意:以上依赖库地址都被修改成了代理镜像地址,因为原始github.com速度极慢,基本下载失败,速度最快也只有几十KB/S,全部切换这个代理镜像后,速度可以在几MB/S。
待所有依赖库下载完成,开始编译:(如果编译失败,确认下grpc版本和gcc版本是否配套)
cd grpc
make
make install
编译安装成功后会在/usr/local/lib生成相应库,在/usr/local/include生成头文件。
proto编译工具安装:
cd grpc
cd third_party
cd protobuf
make
make install
确认是否安装成功:
protoc --version
显示具体版本信息即可:libprotoc 3.11.2
结束语:自己在使用这个github代理镜像前,尝试了各种方法,速度都不尽人意,且失败率高。强烈推荐这个方法,当然也有手动下载依赖库、迁移gitee等方式。