Linux源码编译protobuf

Linux源码编译Protobuf

获取Protobuf源码

1
2
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.12.3/protobuf-cpp-3.12.3.tar.gz
tar -xvzf protobuf-cpp-3.12.3.tar.gz

安装依赖包

1
sudo apt install autoconf automake libtool curl make g++ unzip

源码编译

1
2
3
4
5
./configure --prefix=/home/heroin/thirdparty/protobuf
make
make check
sudo make install
sudo ldconfig # refresh shared library cache.

--prefix设置安装路径,如果不进行设置,将默认安装在 /usr/local

报错指南

报错: g++: internal compiler error: Killed (program cc1plus)

主要原因是内存不足, 临时使用交换分区来解决

1
2
3
sudo dd if=/dev/zero of=/swapfile bs=64M count=16
sudo mkswap /swapfile
sudo swapon /swapfile

编译完成后,释放临时交换分区

1
2
sudo swapoff /swapfile
sudo rm /swapfile

参考

Google Protobuf C++ Installation - Unix

解决: g++: internal compiler error: Killed (program cc1plus)