摘要
最近刚好在Centos和Ubuntu两个系统下源码安装了protobuf,遇到了些小问题,因此写篇博文记录下吧。希望对遭遇同类问题的朋友有所帮助
Centos
其实不管在centos还是Linux下源码安装protobuf都是一样的步骤,分别是下载依赖,然后make。所需的依赖包有:autoconf,automake,libtool等。centos系统下载通过yum管理安装包,那么centos下就可通过下面的命令安装所有依赖:
RUN yum install -y net-tools \
libgomp.x86_64 \
libtool-ltdl-devel.x86_64 \
vim \
psmisc.x86_64 \
libuuid-devel.x86_64 \
zlib-devel.x86_64 \
unixODBC-devel.x86_64 \
mariadb-devel.x86_64 \
dos2unix \
cmake \
make \
gcc-4.8.5 \
gcc-c++-4.8.5 \
autoconf \
automake \
libtool \
git
然后执行开始源码编译安装,通过如下命令搞定:
git clone https://github.com/google/protobuf \
&& cd protobuf \
&& git submodule update --init --recursive \
&& chmod +x -R ./* \
&& ./autogen.sh && ./configure && make && make check && make install
Ubuntu
Ubuntu是通过apt-get来管理安装包,那么在ubuntu下就可以通过如下命令安装所有的依赖
apt-get install -y autoconf && apt-get install -y automake && apt-get install -y libtool \
apt-get install -y cmake && apt-get install -y make \ apt-get install -y git \
下载完依赖之后同样的通过一样的命令,进行源码下载编译安装:
git clone https://github.com/google/protobuf \
&& cd protobuf \
&& git submodule update --init --recursive \
&& chmod +x -R ./* \
&& ./autogen.sh && ./configure && make && make check && make install
可能遇到的问题
问题一
configure: WARNING: no configuration information is in third_party/googletest
解决方案:
在编译安装阶段,执行configure的时候,报如上提示的话,可能会导致makefile文件生成不了,下面就没法make,可以通过如下命令检测并补全third_party目录下所有文件
git submodule update --init --recursive
问题二
make: *** No targets specified and no makefile found. Stop.
解决方案:
这个问题比较玄学,我们在执行上面的源码编译安装命令的时候,make必须紧跟在./configure之后。像我在dockerfile将它两分在两个不同的RUN中,导致docker build的时候报如上的错误
问题三
RPC failed; curl 56 GnuTLS recv error (-9): A TLS packet with unexpected length was received
解决方案:
如果是在基础的docker容器中执行git clone拉去protobuf的源码,可能会有此问题,解决方案如下
apt-get install gnutls-bin
git config --global http.sslVerify false
git config --global http.postBuffer 1048576000