protobuf 编译安装

今天在安装protobuf时,发现网上的protobuf编译安装教程已经落后了,所以记录下来,有需要的朋友可参考。

我是在Ubuntu虚拟机上安装的。

首先在githup上下载源码:

wget -v -O protobuf.zip https://codeload.github.com/protocolbuffers/protobuf/zip/master

然后解压

unzip protobuf.zip

网上的文章是进入该目录后执行:

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

但此时,你会发现目录下缺少configure文件,不过有个autogen.sh的脚本,里面有几行注释:

# Run this script to generate the configure script and other files that will
# be included in the distribution.  These files are not checked in because they
# are automatically generated.

即运行这个脚本以生成configure脚本及其他文件。所以我就运行这个脚本,但却报错了:

+ mkdir -p third_party/googletest/m4
+ autoreconf -f -i -Wall,no-obsolete
./autogen.sh: 37: ./autogen.sh: autoreconf: not found

此时需要安装其他辅助工具:

sudo apt-get install automake autoconf

到这里以为ok了,继续运行脚本autogen.sh,发现还是报错了:

+ mkdir -p third_party/googletest/m4
+ autoreconf -f -i -Wall,no-obsolete
configure.ac:104: error: possibly undefined macro: AC_PROG_LIBTOOL
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
autoreconf: /usr/bin/autoconf failed with exit status: 1

原来还缺少一个依赖:

sudo apt-get install libtool  

完了后运行脚本autogen.sh没问题了,现在开始执行

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

也ok了,后开始编译

make

make check

安装:

sudo make install

配置环境变量:

vim /etc/profile

增加如下2行:

export PATH=$PATH:/usr/local/protobuf/bin/
export PKG_CONFIG_PATH=/usr/local/protobuf/lib/pkgconfig/

因为我使用protobuf来生成go语言的代码,因此,还需安装go语言的生成工具:

go get -u github.com/golang/protobuf/protoc-gen-go

完了后把生成的protoc-gen-go文件拷贝到$GOROOT下。

protobuf编译安装完毕。

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值