一、安装依赖工具集
sudo apt- get install pkg- config
sudo apt- get install autoconf automake libtool make g++ unzip
sudo apt- get install libgflags- dev libgtest- dev
sudo apt- get install clang libc++ - dev
二、下载源代码
git clone https: / / gitee. com/ githubplus/ grpc. git
2.1 修改.gitmodules文件(注意branch不要修改)
[ submodule "third_party/zlib" ]
path = third_party/ zlib
url = https: / / gitee. com/ uddzhi686/ 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
[ submodule "third_party/protobuf" ]
path = third_party/ protobuf
url = https: / / gitee. com/ uddzhi686/ protobuf. git
branch = 3.0 . x
[ submodule "third_party/gflags" ]
path = third_party/ gflags
url = https: / / gitee. com/ uddzhi686/ gflags. git
[ submodule "third_party/googletest" ]
path = third_party/ googletest
url = https: / / gitee. com/ uddzhi686/ googletest. git
[ submodule "third_party/boringssl" ]
path = third_party/ boringssl
url = https: / / gitee. com/ uddzhi686/ boringssl. git
[ submodule "third_party/benchmark" ]
path = third_party/ benchmark
url = https: / / gitee. com/ uddzhi686/ benchmark. git
[ submodule "third_party/boringssl-with-bazel" ]
path = third_party/ boringssl- with- bazel
url = https: / / gitee. com/ uddzhi686/ boringssl- with- bazel. git
[ submodule "third_party/cares/cares" ]
path = third_party/ cares/ cares
url = https: / / gitee. com/ uddzhi686/ c- ares. git
branch = cares- 1 _12_0
[ submodule "third_party/bloaty" ]
path = third_party/ bloaty
url = https: / / gitee. com/ uddzhi686/ bloaty. git
[ submodule "third_party/abseil-cpp" ]
path = third_party/ abseil- cpp
url = https: / / gitee. com/ uddzhi686/ abseil- cpp. git
[ submodule "third_party/envoy-api" ]
path = third_party/ envoy- api
url = https: / / gitee. com/ uddzhi686/ data- plane- api. git
[ submodule "third_party/googleapis" ]
path = third_party/ googleapis
url = https: / / gitee. com/ uddzhi686/ googleapis. git
[ submodule "third_party/protoc-gen-validate" ]
path = third_party/ protoc- gen- validate
url = https: / / gitee. com/ uddzhi686/ protoc- gen- validate. git
[ submodule "third_party/udpa" ]
path = third_party/ udpa
url = https: / / gitee. com/ uddzhi686/ udpa. git
[ submodule "third_party/libuv" ]
path = third_party/ libuv
url = https: / / gitee. com/ uddzhi686/ libuv. git
2.2 修改.git/config文件
[ core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[ remote "origin" ]
url = https: / / gitee. com/ githubplus/ grpc. git
fetch = + refs/ heads
2.3 执行同步命令
git submodule sync
2.4 更新第三方源码
git submodule update -- init
三、安装protobuf
cd third_party/ protobuf/
git submodule update -- init -- recursive
. / autogen. sh
. / configure
make
make check
sudo make install
sudo ldconfig
which protoc # 查看安装路径
protoc -- version # 查看安装版本
四、编译
4.1 编译安装gRPC
cd . / grpc
make
sudo make install # 编译安装,默认安装位置为/ usr/ local/
4.2 编译example
cd examples/ cpp/ helloworld/
make # 如果此处出错,可能就是安装有问题,检查前面步骤
. / greeter_server #运行server
# 打开一个新的终端运行client
. / greeter_client # 返回结果:Greeter received: Hello world