前提:
1、gcc version 5.4.0 (GCC), g++ (GCC) 5.4.0
2、cmake version 3.17.0-rc3
3、GNU Make 3.82
4、Linux test 5.12.2-1.el7.elrepo.x86_64
步骤:
1、如果国外网速不好,则可以使用国内镜像下载:
git clone https://gitee.com/githubplus/grpc.git
直接用master版本肯定有点多,所以这里按照网上的查询选择了一个版本,同时设置他们对应的submodule文件,也就是对应的版本进行下载。
git checkout v1.20.0
2、因为编译grpc需要依赖很多第三方组件,如protobuf等,则也需要将他的submodule文件改为国内镜像,这样下载也要快一些。
修改.gitmodules文件
[submodule "third_party/zlib"]
path = third_party/zlib
url = https://gitee.com/githubplus/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://gitee.com/githubplus/protobuf.git
branch = 3.0.x
[submodule "third_party/gflags"]
path = third_party/gflags
url = https://gitee.com/githubplus/gflags.git
[submodule "third_party/googletest"]
path = third_party/googletest
url = https://gitee.com/githubplus/googletest.git
[submodule "third_party/boringssl"]
path = third_party/boringssl
url = https://gitee.com/githubplus/boringssl.git
[submodule "third_party/benchmark"]
path = third_party/benchmark
url = https://gitee.com/githubplus/benchmark.git
[submodule "third_party/boringssl-with-bazel"]
path = third_party/boringssl-with-bazel
url = https://gitee.com/githubplus/boringssl.git
[submodule "third_party/cares/cares"]
path = third_party/cares/cares
url = https://gitee.com/githubplus/c-ares.git
branch = cares-1_12_0
[submodule "third_party/bloaty"]
path = third_party/bloaty
url = https://gitee.com/githubplus/bloaty.git
[submodule "third_party/abseil-cpp"]
path = third_party/abseil-cpp
url = https://gitee.com/githubplus/abseil-cpp
[submodule "third_party/libcxxabi"]
path = third_party/libcxxabi
url = https://gitee.com/githubplus/libcxxabi.git
branch = release_60
[submodule "third_party/libcxx"]
path = third_party/libcxx
url = https://gitee.com/githubplus/libcxx.git
branch = release_60
[submodule "third_party/data-plane-api"]
path = third_party/data-plane-api
url = https://gitee.com/githubplus/data-plane-api.git
[submodule "third_party/googleapis"]
path = third_party/googleapis
url = https://gitee.com/githubplus/googleapis.git
[submodule "third_party/protoc-gen-validate"]
path = third_party/protoc-gen-validate
url = https://gitee.com/githubplus/protoc-gen-validate.git
[submodule "third_party/upb"]
path = third_party/upb
url = https://gitee.com/githubplus/upb.git
git submodule update --init
因为依赖的protobuf也很大,也需要设置protobuf的submodule文件
cd third_party/protobuf,类似修改protobuf的.gitmodules后
[submodule "third_party/benchmark"]
path = third_party/benchmark
url = https://gitee.com/githubplus/benchmark.git
[submodule "third_party/googletest"]
path = third_party/googletest
url = https://gitee.com/githubplus/googletest.git
ignore = dirty
执行git submodule update --init
这里好像也要先编译才行:不过不先编译也可以把后面的grpc编译通过。但是如果再编译example/cpp/helloword时候就出错,所以还是需要编译。
./autogen.sh
./configure
make -j8
make install
回到grpc目录:
mkdir -p cmake/build
cd cmake/build/
cmake …/…
make -j8
make install