您的位置:首页 > 其它

protobuf 编译安装

2018-08-23 16:58 218 查看

今天在安装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的脚本,里面有几行注释:

[code]# 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脚本及其他文件。所以我就运行这个脚本,但却报错了:

[code]+ 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,发现还是报错了:

[code]+ 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行:

[code]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编译安装完毕。

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: