protobuf grpc安装

linux环境

注:如果缺少依赖安装依赖

sudo apt-get install autoconf automake libtool make g++ unzip zlib1g zlib1g.dev

protobuf

注:
  • 要安装grpc需要的版本
  • 需要卸载Ubuntu自带版本 apt-get remove libprotobuf-dev
步骤:
  • git clone -b v3.7.0 https://github.com/google/protobuf.git
    
  • git submodule update --init --recursive
    
  • ./autogen.sh
    
  • ./configure

  • make

  • make install

  • ldconfig # refresh shared library cache.
    

grpc

源码 官网

如果在官网上下载失败

可使用国内码云下载:https://gitee.com/mirrors/grpc-framework

如果之前安装好prtobuf则直接安装
  • git clone https://github.com/grpc/grpc
  • git submodule update --init
  • make
  • sudo make install
使用grpc里的protobuf安装
  1. 因为之前安装过其他版本所以需要卸载:apt remove protobuf-compiler-grpc

  2. GRPC 默认使用 protobuf 作为消息格式,为 protoc 是 protobuf 协议的编译器,因此,在构建 GRPC 之前确保 protoc 已经安装。

  3. git clone https://gitee.com/mirrors/grpc-framework.git

  4. 上面的地址是码云上的地址,官方的方式是 git clone https://github.com/grpc/grpc

  5. git submodule update --init
    
make
sudo make install
问题使用国内镜像git submodule update --init还是会卡

最终使用了github加速,在windows下下载,在Linux上安装

  • git clone -b v1.22.0 https://github.com/grpc/grpc.git 克隆最新的版本

  • git submodule update --init

  • cd third_party/protobuf/
    git submodule update --init --recursive #确保克隆子模块,更新第三方源码
    
  • 拷贝到Linux

  • make

windows 环境

安装依赖
安装perl

下载地址https://www.activestate.com/products/activeperl/

安装go
下载源码
  • git clone -b v1.22.0 https://github.com/grpc/grpc.git 克隆最新的版本
  • git submodule update --init
安装第三方库

下载源码后,可以在源码根目录下找到 .gitmodules 文件,该文件是 git 用来描述依赖库的,许多库通过git submodule update --init下载不下来只能手动下载

  • cd third_party
  • git clone https://github.com/protocolbuffers/protobuf.git
  • git clone https://github.com/madler/zlib.git
  • git clone https://github.com/google/boringssl.git boringssl
  • 也可以下载指定版本的protobuf
使用cmake配置vs生成

[外链图片转存失败(img-EBVffgda-1567583933795)(…\img\17.png)]

  • 点configure 配置在点Generate生成
  • 用vs 打开grpc.sln ,vs版本要和camke 设置的版本一致
  • 右键ALL_BUILD生成
使用
 .\protoc.exe -I . --cpp_out=. --grpc_out=. --plugin=protoc-gen-grpc=.\grpc_cpp_plugin.exe bukong_task.proto
用到的库
grpc++_unsecure.lib 不适用ssl加密的核心库,这个库必须放前面,不然解析不了ip
libprotobufd.lib  必须的库
grpc.lib          使用SSL加密的库,C核心库,依赖ssl
gpr.lib           必须的库,grpc库依赖
grpc++.lib        使用SSL加密的库,C++需要,依赖ssl
grpc++_cronet.lib  依赖WS2_32.lib
zlibd.lib
zlibstaticd.lib    zlib压缩库,需要
grpc_cronet.lib
grpc_unsecure.lib  不使用ssl加密的库,依赖grpc_unsecure.lib
ssl.lib             openssl库
WS2_32.Lib          网上找的
address_sorting.lib 不添加解析不了IP会报无法解析的外部符号 address_sorting_init
cares.lib         不添加会无法解析的外部符号 _ares_library_init
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值