ubuntu 20.04虚拟机安装GRPC
根据文档进行clone和编译:https://github.com/grpc/grpc/blob/master/BUILDING.md
首先安装依赖环境:
apt-get install build-essential autoconf libtool pkg-config
apt-get install cmake
apt-get install clang libc++-dev
然后将gitee上的镜像源码clone到本地:
git clone https://gitee.com/chuansao825/grpc.git
然后
cd grpc
修改 .gitmodules 文件,将其中每一项github的url找出,然后拉取github的原仓库到自己的gitee仓库,并替换url。即
[submodule "third_party/abseil-cpp"]
	path = third_party/abseil-cpp
	url = https://gitee.com/chuansao825/abseil-cpp.git
[submodule "third_party/benchmark"]
	path = third_party/benchmark
	url = https://gitee.com/chuansao825/benchmark.git
[submodule "third_party/bloaty"]
	path = third_party/bloaty
	url = https://gitee.com/chuansao825/bloaty.git
[submodule "third_party/boringssl-with-bazel"]
	path = third_party/boringssl-with-bazel
	url = https://gitee.com/chuansao825/boringssl.git
[submodule "third_party/cares/cares"]
	path = third_party/cares/cares
	url = https://gitee.com/chuansao825/c-ares.git
[submodule "third_party/envoy-api"]
	path = third_party/envoy-api
	url = https://gitee.com/chuansao825/data-plane-api.git
[submodule "third_party/googleapis"]
	path = third_party/googleapis
	url = https://gitee.com/chuansao825/googleapis.git
[submodule "third_party/googletest"]
	path = third_party/googletest
	url = https://gitee.com/chuansao825/googletest.git
[submodule "third_party/libuv"]
	path = third_party/libuv
	url = https://gitee.com/chuansao825/libuv.git
[submodule "third_party/opencensus-proto"]
	path = third_party/opencensus-proto
	url = https://gitee.com/chuansao825/opencensus-proto.git
[submodule "third_party/opentelemetry"]
	path = third_party/opentelemetry
	url = https://gitee.com/chuansao825/opentelemetry-proto.git
[submodule "third_party/protobuf"]
	path = third_party/protobuf
	url = https://gitee.com/chuansao825/protobuf.git
[submodule "third_party/protoc-gen-validate"]
	path = third_party/protoc-gen-validate
	url = https://gitee.com/chuansao825/protoc-gen-validate.git
[submodule "third_party/re2"]
	path = third_party/re2
	url = https://gitee.com/chuansao825/re2.git
[submodule "third_party/xds"]
	path = third_party/xds
	url = https://gitee.com/chuansao825/xds.git
[submodule "third_party/zlib"]
	path = third_party/zlib
	url = https://gitee.com/chuansao825/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
并同步更新子模块的url:
git submodule sync
然后执行
git submodule update --init 
当子模块成功安装后,使用CMAKE进行Build。
mkdir -p cmake/build
cd cmake/build
cmake ../..
make
(make这一步速度很慢)
build成功:

然后进行install。首先要build并install子模块,根据官方给的脚本:
#!/bin/bash
# Copyright 2017 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#在grpc目录下
set -ex
#cd "$(dirname "$0")/../../.."
# Install openssl (to use instead of boringssl)
apt-get update && apt-get install -y libssl-dev
# Use externally provided env to determine build parallelism, otherwise use default.
GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS=${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS:-4}
# Install absl
mkdir -p "third_party/abseil-cpp/cmake/build"
pushd "third_party/abseil-cpp/cmake/build"
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE ../..
make "-j${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS}" install
popd
# Install c-ares
# If the distribution provides a new-enough version of c-ares,
# this section can be replaced with:
# apt-get install -y libc-ares-dev
mkdir -p "third_party/cares/cares/cmake/build"
pushd "third_party/cares/cares/cmake/build"
cmake -DCMAKE_BUILD_TYPE=Release ../..
make "-j${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS}" install
popd
# Install protobuf
mkdir -p "third_party/protobuf/cmake/build"
pushd "third_party/protobuf/cmake/build"
cmake -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release ..
make "-j${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS}" install
popd
# Install re2
mkdir -p "third_party/re2/cmake/build"
pushd "third_party/re2/cmake/build"
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE ../..
make "-j${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS}" install
popd
# Install zlib
mkdir -p "third_party/zlib/cmake/build"
pushd "third_party/zlib/cmake/build"
cmake -DCMAKE_BUILD_TYPE=Release ../..
make "-j${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS}" install
popd
# Just before installing gRPC, wipe out contents of all the submodules to simulate
# a standalone build from an archive
# shellcheck disable=SC2016
git submodule foreach 'cd $toplevel; rm -rf $name'
# Install gRPC
mkdir -p "cmake/build"
pushd "cmake/build"
cmake \
  -DCMAKE_BUILD_TYPE=Release \
  -DgRPC_INSTALL=ON \
  -DgRPC_BUILD_TESTS=OFF \
  -DgRPC_CARES_PROVIDER=package \
  -DgRPC_ABSL_PROVIDER=package \
  -DgRPC_PROTOBUF_PROVIDER=package \
  -DgRPC_RE2_PROVIDER=package \
  -DgRPC_SSL_PROVIDER=package \
  -DgRPC_ZLIB_PROVIDER=package \
  ../..
make
make install
popd
#测试是否安装成功
# Build helloworld example using cmake,在grpc目录下
mkdir -p "examples/cpp/helloworld/cmake/build"
pushd "examples/cpp/helloworld/cmake/build"
cmake ../..
make "-j${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS}"
popd
得到结果

为了测试是否安装成功,在上述生产的example的目录下使用两个终端先后开启server和client,如下所示:



 
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号