初解
Google Protocol Buffers浅析(一)
(1)安装依赖工具
sudo apt-get install autoconf automake libtool curl make g++ unzip
(2)在protobuf github上获取版本信息及源码链接,用wget下载:
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.7.1/protobuf-cpp-3.7.1.tar.gz
(3)解压
tar -xzvf protobuf-cpp-3.7.1.tar.gz
(4)根据官网安装教程依次执行
cd protobuf-3.7.1
./autogen.sh
./configure
make
make check
sudo make install
sudo ldconfig
成功安装,
也可以直接二进制安装:
// 安装protoc
$ wget https://github.com/protocolbuffers/protobuf/releases/download/v3.17.3/protoc-3.17.3-osx-x86_64.zip
$ unzip protoc-3.17.3-osx-x86_64.zip
$ cd protoc-3.17.3-osx-x86_64
$ cp bin/protoc /home/.local/bin/protoc
$ cp -r include/google /home/.local/include/google
protoc --version
生成命令
一文了解protoc的使用
解决protobuf import路径的问题
protoc --proto_path=../../../ --proto_path=./ --python_out=./ proto_parser.proto
官方api
Python Generated Code