美文网首页
gRPC 和 protobuf 的安装

gRPC 和 protobuf 的安装

作者: 酷酷滴小爽哥 | 来源:发表于2018-08-05 14:18 被阅读0次

在着手 C++ 的 TensorFlow serving mnist client 的过程中,不断采坑,被环境安装折磨的不行。现本着学习回顾,特总结,方便后面同学避免在环境搭建上出现问题。本次完全新建了个环境,在新环境上实验成功。系统为: Ubuntu 16.04.

如果你只是单纯的想安装 protobuf 那么对于安装的 protobuf 版本并没有要求。但是如果要安装 gRPC 的话,那么需要和 gRPC 版本有所对应,否则私自安装个 protobuf 并没有太大意义,因为 clone 下来的 grpc 文件夹里就有对应的文件夹,在这里安装 protobuf 可以保证安装 grpc 不出错。安装 grpc 不建议先单独编译安装 protobuf,但是本着学习的目的,下面依次介绍了单独安装 protobuf 和安装 grpc&protobuf 的方法。

安装 protobuf

1.下载 protobuf 并解压。下载地址:https://github.com/google/protobuf/releases

2.进入解压后的文件目录,执行如下操作:

  • ./configure

通常建议安装到 /usr/local 目录下,执行 configure 时,指定 --prefix=/usr/local/protobuf 即可

  • make

  • make check

  • sudo make install

3.安装成功后,将它的 binlib 目录分别加入到 PATH 和 LD_LIBRARY_PATH 环境变量,以方便直接调用。

设置环境变量过程:编辑 /etc/profile,在文件末尾添加:

export PATH=$PATH:/usr/local/protobuf/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/protobuf/lib

安装 gRPC

1.安装依赖:

  • 首先安装 pkg-configsudo 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

2.下载GRPC

git clone https://github.com/grpc/grpc.git
cd grpc
git submodule update --init  //更新第三方源码

4.安装 protobuf 源码:

cd third_party/protobuf/
git submodule update --init --recursive    //确保克隆子模块,更新第三方源码
./autogen.sh    //生成配置脚本
./configure    //生成Makefile文件,为下一步的编译做准备,可以加上安装路径:--prefix=path
make          //从Makefile读取指令,然后编译
make check   //可能会报错,但是不影响

sudo make install

从 Makefile 读取指令,安装到指定位置,默认为 /usr/local/,也可以指定安装目录:--prefix=path。卸载的命令为 make uninstall

相关命令说明:

  • make clean:清除编译产生的可执行文件及目标文件 (object file,*.o)

  • make distclean:除了清除可执行文件和目标文件外,把 configure 所产生的 Makefile 也清除掉。

  • sudo ldconfig:更新共享库缓存

  • which protoc:查看软件的安装位置

  • protoc --version:检查是否安装成功

5.安装GRPC

cd ../..  //进入 grpc 根目录
make       //从Makefile读取指令,然后编译
sudo make install

从 Makefile 读取指令,安装到指定位置,默认为 /usr/local/,具体的位置在 binlib 目录下。

6.测试

在 gRPC 目录下:

cd examples/cpp/helloworld/
make                //编译
./greeter_server  //服务器
./greeter_client   //客户端

出现 Greeter received: Hello world 则表示安装成功。

相关文章

网友评论

      本文标题:gRPC 和 protobuf 的安装

      本文链接:https://www.haomeiwen.com/subject/eqsbvftx.html