centos7中安裝protobuf-c
?
前言
設(shè)備服務(wù)與設(shè)備端通訊,設(shè)備服務(wù)使用Go構(gòu)建,使用protobuf格式與設(shè)備端通訊,設(shè)備端采用stm32系列mcu,使用C語言開發(fā),所以要生成protobuf C語言版協(xié)議庫。
步驟
1.準(zhǔn)備
yum -y install autoconf automake libtool
yum -y install gcc gcc-c++
2.安裝protobuf
protobuf版本地址:
使用wget下載tar.gz包,tar -zxvf 解壓;
在解壓包中,運行./autogen.sh,然后./configure,make & make install 安裝,當(dāng)然 ./configure --prefix=/usr/local/protobuf 設(shè)置安裝目錄;
測試:protoc命令;
這時還不能生成c語言代碼。
3.安裝protobuf-c
設(shè)置環(huán)境變量:export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig,目錄根據(jù)安裝目錄定義,這是未配置安裝目錄下的配置;
protobuf-c版本地址:
使用wget下載tar.gz包,tar -zxvf 解壓;
在解壓包中,運行./autogen.sh,然后./configure,make & make install 安裝;
測試:protoc --c_out=. msg.proto,生成.h和.c文件。
4.使用
使用時需要引用:
解析后,及時free。
記錄于 2020-06-21
?

浙公網(wǎng)安備 33010602011771號