文章目录
- cmake升级
- grpc安装
- protobuf安装
- abseil安装
- 测试环境
cmake升级
首先我感觉这个跟cmake的版本有关,最好先将cmake升级到3.17以上
root@VM-16-5-ubuntu:/home/ubuntu/lib/grpc# cmake --version
cmake version 3.18.0
下载cmake各版本安装包
下载地址:https://cmake.org/files/
选择需要的版本下载,我下载的是 v3.18 版本中的 Linux-x86_x64 一类后缀的版本,这个是已经针对 Linux 环境编译好的二进制包。比如我这里下载 cmake-3.18.0-Linux-x86_64.tar.gz。
上传到服务器后解压
tar -xzvf cmake-3.18.0-Linux-x86_64.tar.gz
将解压后的二进制包放到一个不会被你误删的地方
mv cmake-3.18.0-Linux-x86_64 /home/
找到原先低版本的cmake二进制包,将其拷贝备份到一个不会被你误删的地方
which cmake
/usr/bin/cmake
mv /usr/bin/cmake /home/cmake-3.18.0-Linux-x86_64/
创建软连接
sudo ln -s /home/cmake-3.18.0-Linux-x86_64/bin/cmake /usr/bin/cmake
注意这里一定要用绝对路径,不能用相对路径,不然不行。
然后运行cmake --version,cmake版本就变成你想要的版本啦。
grpc安装
github grpc c++官网安装教程
https://github.com/grpc/grpc/blob/master/BUILDING.md
grpc c++安装教程参考链接
javascript:void(0)
javascript:void(0)
git clone https://gitee.com/mirrors/grpc.git
cd grpc
替换.gitmodules文件
[submodule "third_party/zlib"]
path = third_party/zlib
url = https://gitee.com/Xprice/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/Xprice/protobuf.git
[submodule "third_party/googletest"]
path = third_party/googletest
url = https://gitee.com/Xprice/googletest.git
[submodule "third_party/benchmark"]
path = third_party/benchmark
url = https://gitee.com/Xprice/benchmark.git
[submodule "third_party/boringssl-with-bazel"]
path = third_party/boringssl-with-bazel
url = https://gitee.com/Xprice/boringssl.git
[submodule "third_party/re2"]
path = third_party/re2
url = https://gitee.com/Xprice/re2.git
[submodule "third_party/cares/cares"]
path = third_party/cares/cares
url = https://gitee.com/Xprice/c-ares.git
branch = cares-1_12_0
[submodule "third_party/bloaty"]
path = third_party/bloaty
url = https://gitee.com/Xprice/bloaty.git
[submodule "third_party/abseil-cpp"]
path = third_party/abseil-cpp
url = https://gitee.com/Xprice/abseil-cpp.git
branch = lts_2020_02_25
[submodule "third_party/envoy-api"]
path = third_party/envoy-api
url = https://gitee.com/Xprice/data-plane-api.git
[submodule "third_party/googleapis"]
path = third_party/googleapis
url = https://gitee.com/Xprice/googleapis.git
[submodule "third_party/protoc-gen-validate"]
path = third_party/protoc-gen-validate
url = https://gitee.com/Xprice/protoc-gen-validate.git
[submodule "third_party/udpa"]
path = third_party/udpa
url = https://gitee.com/Xprice/udpa.git
[submodule "third_party/libuv"]
path = third_party/libuv
url = https://gitee.com/Xprice/libuv.git
[submodule "third_party/opencensus-proto"]
path = third_party/opencensus-proto
url = https://gitee.com/Xprice/opencensus-proto.git
git submodule update --init
mkdir -p cmake/build
cd cmake/build
cmake ../..
make
sudo make install
这个命令不知道对结果是否有影响,建议执行一下
cp -r /home/ubuntu/lib/grpc/third_party/abseil-cpp/absl/ /usr/local/include/
protobuf安装
不用手动安装protobuf,不然版本可能不匹配,必须在 grpc 执行 git submodule update --init 命令之后生成的 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
cd third_party/abseil-cpp/
mkdir build
cd build
cmake ..
make
sudo make install
abseil安装
可能会有 abseil 的安装
cd third_party/protobuf/
./autogen.sh
./configure --prefix=/usr/local
make
sudo make install
测试环境
cd grpc/examples/cpp/helloworld/
mkdir build
cd build/
cmake ..
make
./greeter_server
Server listening on 0.0.0.0:50051
./greeter_client
Greeter received: Hello world