1 下载源码
git clone https://github.com/grpc/grpc.git
cd grpc
git submodule update --init #跟新第三方源
2 安装
查看 BUILDING.md 先安装依赖项
$ [sudo] apt-get install build-essential autoconf libtool pkg-config
If you plan to build from source and run tests, install the following as well:
$ [sudo] apt-get install libgflags-dev libgtest-dev
$ [sudo] apt-get install clang libc++-dev
再如下操作:
make
sudo make install prefix=/usr/local/
sudo ldconfig
测试 protobuf
protoc --version
输出如下,已经给安装上了最新的protobuf
libprotoc 3.6.1
遇到错误:1
/grpc/gens/src/proto/grpc/core/stats.pb.cc:187:13: error: ‘dynamic_init_dummy_src_2fproto_2fgrpc_2fcore_2fstats_2eproto’ defined but not used [-Werror=unused-variable]
static bool dynamic_init_dummy_src_2fproto_2fgrpc_2fcore_2fstats_2eproto = []()
^
cc1plus: all warnings being treated as errors
解决办法
找到Makefile,去掉其中-Werror ,make clean 重新编译。
遇到错误:2
protobuf与grpc 所要求的版本不一致,按要求安装就好。
3 跑示例程序
进入 /examples/cpp/route_guide/:
cd examples/cpp/route_guide
执行
make route_guide.grpc.pb.cc route_guide.pb.cc
其实执行的语句为:
protoc -I ../../protos --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` ../../protos/route_guide.proto
protoc -I ../../protos --cpp_out=. ../../protos/route_guide.proto
最后make生成可执行文件
make
先启动server,再启动client
./route_guide_server
./route_guide_client
结果如下:

|