最近项目需要使用google 的protocol buffers,就看了下protobuf相关内容,发现网上中文资料大多停留在protobuf2阶段,经查阅protobuf已经更新到3.11.4版本了,并且3系列比2优化的内容更多,使用也更方便。下面记录下从下载源码,编译protobuf库,到测试使用。
1.安装protobuf3.11.4
1.1 解决编译protobuf库文件工具
如果你已经成功在centos下安装了Qt,并可以正常执行编译运行程序,此步骤不需要。
yum -y install autoconf automake libtool curl make g++ unzip
1.2 下载源码并安装
git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf
git submodule update --init --recursive
./autogen.sh
./configure
make
make check
make install # root
ldconfig # refresh shared library cache.
安装库中出现的问题:
我自己第一次编译protobuf源码的时候,没有clone子模块,
即recursive,在执行make check的时候报错了,如下图:
在报错的情况下,依然执行了make install, 库安装成功了。
but but 后来在看官方文档的时候,发现了这样一句话: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.
文档也没说有啥风险,毕竟开始学,也不清楚啥情况,于是就再编译安装一次吧。
后续又在已经make的源码下,执行clone子模块,继续报错,于是就又重新clone了protobuf源码,按照上述步骤执行,就没有报错了。
注意安装后库的路径:/usr/local/lib下,后面用得着。
成功安装protobuf3.11.4
linux(centos8.1)下使用qt5.12.7 no-gui测试protobuf3.11.4