ProtoBuffer交叉编译

本文详细介绍了如何在Linux环境下,为arm架构交叉编译Protocol Buffers(protobuf)2.6.1版本。首先,执行autogen.sh脚本并进行相应修改,然后配置并安装protobuf到本地目录。接着,通过指定交叉编译器路径、添加-fPIC编译选项和protoc路径,成功完成交叉编译。该过程对于在不同架构设备上部署protobuf应用至关重要。
摘要由CSDN通过智能技术生成

  • Protobuf github 官网 GitHub - protocolbuffers/protobuf: Protocol Buffers - Google's data interchange format

    • 我们一般使用2.6.1
    • 先编译PC版本(此步骤很重要 因为需要proto-c生成代码)

      • 解压protobuf-2.6.1.tar.gz

      • ./autogen.sh 直接执行会报错  可以把./autogen.sh脚本里这部分替换

  • echo "Google Test not present.  Fetching gtest-1.5.0 from the web..."
    curl <http://googletest.googlecode.com/files/gtest-1.5.0.tar.bz2> | tar jx
    mv gtest-1.5.0 gtest
    
    wget <https://github.com/google/googletest/archive/release-1.5.0.tar.gz>
    tar xzvf release-1.5.0.tar.gz  #发现下载的文件没有后缀名,所以我改成tar xzvf release-1.5.0
    mv googletest-release-1.5.0 gtest
    

    再次执行./autogen.sh

  • ./configure --prefix=/home/work/protobuf/pc_protobuf
    • make install (注意权限)

    • make

  • 交叉编译

    • 跑下以下脚本 

      #!/bin/bash
      compiler_root_path="/home/softwares/gcc-linaro-6.5.0-2018.12-x86_64_aarch64-linux-gnu"
      make_c_compiler=${compiler_root_path}/bin/aarch64-linux-gnu-gcc
      make_cxx_compiler=${compiler_root_path}/bin/aarch64-linux-gnu-g++
      
      echo ${make_c_compiler}
      echo ${make_cxx_compiler}
      ./configure --host=arm-linux CC=${make_c_compiler} CXX=${make_cxx_compiler} CXXFLAGS=-fPIC --prefix=/home/work/protobuff/arm_protobuf/ --disable-dependency-tracking --with-protoc=/home/work/protobuf/pc_protobuf/bin/protoc
      

      注意:

      1.要配置好交叉编译工具

      2.一定要加上编译选项 CXXFLAGS=-fPIC

      3.一定要加上--with-protoc=/home/work/protobuf/pc_protobuf/bin/protoc 否则会自动用交叉编译的protoc去生成proto,因为编译过程往往是X86所以会报执行错误 lt-protoc: cannot execute binary file: Exec format error

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值