protobuf库在Linux下编译,CentOS 7下protobuf的源码编译安装

protobuf的github地址:https://github.com/google/protobuf支持多种语言,有多个语言的版本,本文采用的是在CentOS 7下编译源码进行安装。

github上有详细的安装说明:https://github.com/google/protobuf/blob/master/src/README.md

1、确定centos7上已经安装了下面的软件,或者直接用yum进行更新

autoconf

automake

libtool

curl (used to download gmock)

make

g++

unzip

2、下载源码包,解压,编译安装

地址:https://github.com/google/protobuf/releases

选择Source code(tar.gz)下载

tar -zxvf protobuf-3.1.0.tar.gz -C /usr/local/cd protobuf-3.1.0/# 如果使用的不是源码,而是release版本 (已经包含gmock和configure脚本),可以略过这一步

./autogen.sh# 指定安装路径

./configure --prefix=/usr/local/protobuf

#编译make# 测试,这一步很耗时间makecheckmake install# refresh shared library cache.

ldconfig

注意make check这一步会花费比较多的时间

00cbbf3f81f86e7fb72f911dd4e92219.png

3、设置一下环境变量 /etc/profile

# (动态库搜索路径) 程序加载运行期间查找动态链接库时指定除了系统默认路径之外的其他路径

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

# (静态库搜索路径) 程序编译期间查找动态链接库时指定查找共享库的路径

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/protobuf/lib

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

4、查看版本

protoc --version

之后,对于相同的系统环境,就不需要再编译了,直接将编译好的protobuf(目录:/usr/local/protobuf)分发到其他计算机,设置环境变量即可。

0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值