根据以上两个博主的方法再结合自己实际安装的遇到的问题重新整合出来此版本。
protobuf可以直接在GitHub上面下载,地址为:GitHub - protocolbuffers/protobuf: Protocol Buffers - Google's data interchange format
可以在上面选择自己需要的版本,我当前需要安装的版本是3.1.x的,我是直接在上面下载的zip压缩包,也可以使用克隆方法获取(我通过克隆的方法获取不了代码,所以直接下载的压缩包)。
在下载目录下使用命令解压文件:
$ unzip protobuf-3.1.x.zip
可以将解压的文件移到其他位置(看自己需求,我是在下载目录直接解压安装的),然后进入到解压的目录下:
$ cd protobuf-3.1.x
打开当前目录下README.md文件
在文件中找到这段有用的文字,如果需要安装二进制文件,则查阅src目录下中README.md文件,随后再打开此文件,里面详细介绍了安装protobuf的流程,将src/README.md中的安装流程附上,在protobuf-3.1.x目录下执行下列命令即可:
To build protobuf from source, the following tools are needed:
* autoconf
* automake
* libtool
* curl (used to download gmock)
* make
* g++
* unzipOn Ubuntu, you can install them with:
$ sudo apt-get install autoconf automake libtool curl make g++ unzip
On other platforms, please use the corresponding package managing tool to
install them before proceeding.If you get the source from github, you need to generate the configure script
first:$ ./autogen.sh
This will download gmock source (which is used for C++ Protocol Buffer
unit-tests) to the current directory and run automake, autoconf, etc.
to generate the configure script and various template makefiles.You can skip this step if you are using a release package (which already
contains gmock and the configure script).To build and install the C++ Protocol Buffer runtime and the Protocol
Buffer compiler (protoc) execute the following:$ ./configure
$ make
$ make check
$ sudo make install
$ sudo ldconfig # refresh shared library cache.If "make check" fails, you can still install, but it is likely that
some features of this library will not work correctly on your system.
Proceed at your own risk.For advanced usage information on configure and make, please refer to the
autoconf documentation:http://www.gnu.org/software/autoconf/manual/autoconf.html#Running-configure-Scripts
按照上述安装完成后,执行protoc --version,会出现当前libporoto的版本信息:
$ protoc --version
libprotoc 3.1.0
以上,安装完毕。
如果需要更新版本,直接将新版本下载按照上述流程即可,新版本会覆盖旧版本。