gRPC快速编译

一、安装依赖工具集

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/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master
 
# 注意:上面的内容不需要改变,下面使我们主要修改地址的地方
[submodule "third_party/abseil-cpp"]
	url = https://gitee.com/uddzhi686/abseil-cpp.git
[submodule "third_party/benchmark"]
	url = https://gitee.com/uddzhi686/benchmark.git
[submodule "third_party/bloaty"]
	url = https://gitee.com/uddzhi686/bloaty.git
[submodule "third_party/boringssl"]
	url = https://gitee.com/uddzhi686/boringssl.git
[submodule "third_party/boringssl-with-bazel"]
	url = https://gitee.com/uddzhi686/boringssl-with-bazel.git
[submodule "third_party/cares/cares"]
	url = https://gitee.com/uddzhi686/c-ares.git
[submodule "third_party/data-plane-api"]
	url = https://gitee.com/uddzhi686/data-plane-api.git
[submodule "third_party/gflags"]
	url = https://gitee.com/uddzhi686/gflags.git
[submodule "third_party/googleapis"]
	url = https://gitee.com/uddzhi686/googleapis.git
[submodule "third_party/googletest"]
	url = https://gitee.com/uddzhi686/googletest.git
[submodule "third_party/libcxx"]
	url = https://gitee.com/githubplus/libcxx.git
[submodule "third_party/libcxxabi"]
	url = https://gitee.com/githubplus/libcxxabi.git
[submodule "third_party/protobuf"]
	url = https://gitee.com/githubplus/protobuf.git
[submodule "third_party/protoc-gen-validate"]
	url = https://gitee.com/githubplus/protoc-gen-validate.git
[submodule "third_party/upb"]
	url = https://gitee.com/githubplus/upb.git
[submodule "third_party/zlib"]
	url = https://gitee.com/uddzhi686/zlib.git

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值