centos 7.x protobuf交叉編譯protobuf-c

一、準備環境

1、依賴庫

yum install automake autoconf libtool git glibc-headers gcc-c++

二、protobuf源碼編譯

源碼連接:https://github.com/protocolbuffers/protobuf/releases

# git clone https://github.com/protocolbuffers/protobuf.git
# cd protobuf
# git submodule update --init --recursive
# ./autogen.sh
# ./configure
# make
# make install
# ldconfig

三、protobuf-c源碼編譯

源碼連接:https://github.com/protobuf-c/protobuf-c

# git clone https://github.com/protobuf-c/protobuf-c.git
# cd protobuf-c
# ./autogen.sh
# ./configure
# make & make install
# cp -r /usr/local/include/protobuf-c/ /usr/include/
# ldconfig

configure編譯中出現以下錯誤:

configure: error: Package requirements (protobuf >= 2.6.0) were not 
met:No package ‘protobuf’ found

解決方案:

查找protobuf.pc所在路徑,並將路徑添加到PKG_CONFIG_PATH環境變量中即可解決編譯問題

# find /usr/ -name "protobuf.pc"
/usr/lib/pkgconfig/protobuf.pc
/usr/local/lib/pkgconfig/protobuf.pc
# export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/

四、編譯完成進行protobuf代碼生成

1、controller_le.proto結構文件

syntax = "proto3";

message master_anchor
{
        fixed64 ui64Addr        = 1;                    // 主機站的64位地址
        double  dbRfdistance    = 2;                    // 基站間的配置距離
}

2、編譯

# protoc-c --c_out=. controller_le.proto

3、編譯生成文件

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章