linux下使用ProtoBuf, 有如下几种安装方式。
configure方式源码编译安装,发现使用的时候cmake找不到protobuf。
于是采用了 cmake 源码的安装方式。
1. 直接安装方式
安装: sudo apt-get install libprotobuf-dev protobuf-compiler
卸载: sudo apt-get remove libprotobuf-dev protobuf-compiler
2. configure方式源码编译安装
sudo apt-get install autoconf automake libtool curl make g++ unzip
git clone https://github.com/google/protobuf.git
cd protobuf
git submodule update --init --recursive
./autogen.sh
./configure --prefix=/usr/local/protobuf # 最好加上后面这个prefix,方便删除
make
make check
sudo make install
sudo ldconfig # refresh shared library cache.
设置环境变量
# (动态库搜索路径) 程序加载运行期间查找动态链接库时指定除了系统默认路径之外的其他路径
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/protobuf/lib
# (静态库搜索路径) 程序编译期间查找动态链接库时指定查找共享库的路径
export LIBRAR