本文记录 Ubuntu 下源码编译安装 Protocol Buffers (或称 protobuf) 的过程.
1. 安装之前
HomePage:https://developers.google.com/protocol-buffers
GitHub:https://github.com/protocolbuffers/protobuf
C++ Installation:https://github.com/protocolbuffers/protobuf/blob/master/src/README.md
1.1 安装必要工具
$ sudo apt-get install autoconf automake libtool curl make g++ unzip
1.3 下载
在下面页面下载所需版本的 protobuf-cpp-[VERSION]..tar.gz
源码压缩包.
https://github.com/protocolbuffers/protobuf/releases?
本文安装的是 2.61 版本.
https://github.com/protocolbuffers/protobuf/releases?after=v2.61
2. 安装和验证
2.1 编译安装
解压缩
$ tar -xzvf protobuf-2.6.1.tar.gz
进入源码包目录
$ cd protobuf-2.6.1/
生成安装配置文件
$ ./configure
编译
$ make -j6
检查编译结果
扫描二维码关注公众号,回复:
12901816 查看本文章

$ make check -j6
...
...
PASS: protobuf-test
PASS: protobuf-lazy-descriptor-test
PASS: protobuf-lite-test
PASS: google/protobuf/compiler/zip_output_unittest.sh
PASS: google/protobuf/io/gzip_stream_unittest.sh
...
...
============================================================================
Testsuite summary for Protocol Buffers 2.6.1
============================================================================
# TOTAL: 5
# PASS: 5
# SKIP: 0
# XFAIL: 0
# FAIL: 0
# XPASS: 0
# ERROR: 0
============================================================================
...
...
安装到系统中
$ sudo make install
更新共享库
$ sudo ldconfig
2.2 验证
安装了 protobuf 的 C++ 运行时环境 (libprotobuf) 和 protobuf 编译器 (protoc).
$ protoc --version
libprotoc 2.6.1
$ whereis protoc
protoc: /usr/local/bin/protoc
$ whereis libprotobuf
libprotobuf: /usr/local/lib/libprotobuf.a /usr/local/lib/libprotobuf.so /usr/local/lib/libprotobuf.la