centos7中安装protobuf-c

 前言

设备服务与设备端通讯,设备服务使用Go构建,使用protobuf格式与设备端通讯,设备端采用stm32系列mcu,使用C语言开发,所以要生成protobuf C语言版协议库。

 

步骤

 

1.准备

yum -y install autoconf automake libtool

yum -y install gcc gcc-c++

 

2.安装protobuf

protobuf版本地址:https://github.com/protocolbuffers/protobuf/releases

使用wget下载tar.gz包,tar -zxvf 解压;

在解压包中,运行./autogen.sh,然后./configure,make & make install 安装,当然 ./configure --prefix=/usr/local/protobuf 设置安装目录;

测试:protoc命令;

这时还不能生成c语言代码。

 

3.安装protobuf-c

设置环境变量:export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig,目录根据安装目录定义,这是未配置安装目录下的配置;

protobuf-c版本地址:https://github.com/timesto/protobuf-c/releases

使用wget下载tar.gz包,tar -zxvf 解压;

在解压包中,运行./autogen.sh,然后./configure,make & make install 安装;

测试:protoc --c_out=. msg.proto,生成.h和.c文件。

 

4.使用

使用时需要引用:https://github.com/timesto/protobuf-c 下的protobuf-c文件;

解析后,及时free。

 

记录于   2020-06-21 

posted @ 2025-09-16 14:08  时代变迁  阅读(20)  评论(0)    收藏  举报