根据部署环境,使用的编程语言选择安装包
这里放上github中的链接:https://github.com/protocolbuffers/protobuf/releases/tag/v3.18.0
我选择的是protobuf-cpp-3.18.tar.gz
然后是在树莓派中解压,解压后依次执行以下步骤:
- ./configure # 这一步是编译工具链依赖分析等
- make
- make check
- sudo make install
- sudo ldconfig
# refresh shared library cache.
记得编译依赖的库, 2.2.0 版本后依赖的内容由pkg-config工具来管理。
换句话说,pkg-config这个工具知道要使用某个package时应该用哪些flag, 哪些libs
Compiling dependent packages
To compile a package that uses Protocol Buffers, you need to pass various flags to your compiler and linker. As of version 2.2.0, Protocol Buffers integrates with pkg-config to manage this. If you have pkg-config installed, then you can invoke it to get a list of flags like so:
pkg-config --cflags protobuf # print compiler flags pkg-config --libs protobuf # print linker flags pkg-config --cflags --libs protobuf # print both
例如:
g++ my_program.c my_proto.pb.cc `pkg-config --cflags --libs protobuf`
安装的最后是检查环节:
默认情况下,protobuf会被安装在/usr/local 目录下,相应的lib在/usr/local/lib下
在一些平台中,这个路径不在LD_LIBRARY_PATH中,注意加上。
pkg-config --cflags --libs protobuf
执行结果如下:
protoco --help执行结果如下
至此,安装篇完成