1004.ubuntu16.04 安装protobuf
1 在线安装protobuf 依赖库
sudo apt-get install autoconf automake libtool curl make g++ unzip
2 下载源码
git clone https://github.com/google/protobuf.git
3 cd protobuf 目录,配置安装路径
./autogen.sh
./configure --prefix=/usr/local/protobuf
4 编译、安装
make
make check
make install
5 配置 环境变量,打开家目录.bashrc文件
建立软连接
创建软链接,保证与ubuntu内置的2.6.1共存
ln -s /usr/local/protobuf/bin/protoc /usr/local/protobuf/bin/protoc3
//创建链接必须使用绝对路径
6 打开 /etc/ld.so.conf 文件,添加依赖库路径
7 ,执行环境变量生效
source .bashrc ,
ldconfig
8 编写protobuf示例
编写文件 game.proto 文件
9 编写写文件 write.cpp
10 编写 read.cpp
11 编译文件
protoc3 --cpp_out=./ ./game.proto //编译proto文件
g++ write.cpp game.pb.cc -o write -lprotobuf -std=c++11 -lpthread //主要 -lpthread 必须 在最后
g++ read.cpp game.pb.cc -o read -lprotobuf -std=c++11 -lpthread
12 执行得到结果