【Linux】rocketmq-client-cpp 2.0.1 编译方法(基于 ARM 64 架构)

以下内容均来自个人笔记并重新梳理,如有错误欢迎指正!如果对您有帮助,烦请点赞、关注、转发!欢迎扫码关注个人公众号!

公众号二维码


背景介绍

近期,笔者同事在进行业务容器适配 ARM 64 的工作,但是遇到无法安装 rocketmq-client-cpp 2.0.1 动态库的问题,最终笔者帮忙解决了该问题。该问题的原因是 X86 架构下可以直接使用官方 yum 源进行安装,但是 ARM 64 架构下官方并未提供 yum 源。

本文基于 rocketmq-client-cpp 2.0.1 版本,通过源码编译方式生成 .so 动态库文件,以下为完整过程。


过程回顾

1、安装依赖(解决报错1)

yum install -y gcc-c++ cmake automake autoconf libtool bzip2-devel zlib-devel

2、下载 & 解压

cd
wget -O rocketmq-client-cpp-2.0.1.tar.gz https://github.com/apache/rocketmq-client-cpp/archive/refs/tags/2.0.1.tar.gz
tar -xzf rocketmq-client-cpp-2.0.1.tar.gz && cd rocketmq-client-cpp-2.0.1

3、修改 build.sh(解决报错2)

# 在函数 BuildBoost 中加入 >>>>>> <<<<<< 之间的内容

BuildBoost() {
  if [ $need_build_boost -eq 0 ]; then
    echo "no need build boost lib"
    return 0
  fi

  cd ${down_dir}
  if [ -e ${fname_boost} ]; then
    echo "${fname_boost} is exist"
  else
    wget http://sourceforge.net/projects/boost/files/boost/${fname_boost_down}
  fi
  tar -zxvf ${fname_boost} &> unzipboost.txt
  boost_dir=$(ls | grep ^boost | grep .*[^gz]$)
  cd ${boost_dir}
  if [ $? -ne 0 ]; then
    exit 1
  fi
  ./bootstrap.sh
  ##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  ./b2 &>/dev/null       # 需要先运行 ./b2 以生成 /root/rocketmq-client-cpp-2.0.1/tmp_down_dir/boost_1_58_0/bin.v2 目录
  sleep 5
  rm -rf /root/rocketmq-client-cpp-2.0.1/tmp_down_dir/boost_1_58_0/bin.v2/project-cache.jam
  cp -p /root/project-cache.jam /root/rocketmq-client-cpp-2.0.1/tmp_down_dir/boost_1_58_0/bin.v2/project-cache.jam
  ##<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  if [ $? -ne 0 ]; then
    exit 1
  fi
  echo "build boost static #####################"
  pwd
  if [ $verbose -eq 0 ]; then
    echo "build boost without detail log."
    ./b2 -j$cpu_num cflags=-fPIC cxxflags=-fPIC --with-atomic --with-thread --with-system --with-chrono --with-date_time --with-log --with-regex --with-serialization --with-filesystem --with-locale --with-iostreams threading=multi link=static release install --prefix=${install_lib_dir} &> boostbuild.txt
  else
    ./b2 -j$cpu_num cflags=-fPIC cxxflags=-fPIC --with-atomic --with-thread --with-system --with-chrono --with-date_time --with-log --with-regex --with-serialization --with-filesystem --with-locale --with-iostreams threading=multi link=static release install --prefix=${install_lib_dir}
  fi
  if [ $? -ne 0 ]; then
    exit 1
  fi
}

4、修改 CMakeLists.txt(解决报错2)

sed -i "s/list(APPEND CXX_FLAGS \"-m64\")/#list(APPEND CXX_FLAGS \"-m64\")/g" CMakeLists.txt 
grep "m64" CMakeLists.txt

5、修改 project-cache.jam(解决报错2)

# 将以下 3 行改为 true(获取文件方法:第一次执行 build.sh 脚本,失败退出后复制/root/rocketmq-client-cpp-2.0.1/tmp_down_dir/boost_1_58_0/bin.v2/project-cache.jam)
module config-cache {
  ...
  set "arm-<target-os>linux-<toolset-gcc:version>4.8.5-<toolset>gcc" : "true" ;
  ...
  set "arm-<address-model>64-<target-os>linux-<toolset-gcc:version>4.8.5-<toolset>gcc" : "true" ;
  ...
  set "gcc visibility-<address-model>64-<target-os>linux-<toolset-gcc:version>4.8.5-<toolset>gcc" : "true" ;
  ...
}

6、执行脚本

bash build.sh

# 生成的文件位于 /root/rocketmq-client-cpp-2.0.1/bin 目录


附录

报错1:
libs/iostreams/src/bzip2.cpp:20:56: fatal error: bzlib.h: No such file or directory
 #include "bzlib.h"  // Julian Seward's "bzip.h" header.
                                                        ^
compilation terminated.

    "g++"  -ftemplate-depth-128 -O3 -finline-functions -Wno-inline -Wall -pthread -fPIC -fPIC -DBOOST_ALL_NO_LIB=1 -DBOOST_IOSTREAMS_USE_DEPRECATED -DNDEBUG  -I"." -c -o "bin.v2/libs/iostreams/build/gcc-4.8.5/release/link-static/threading-multi/bzip2.o" "libs/iostreams/src/bzip2.cpp"

...failed gcc.compile.c++ bin.v2/libs/iostreams/build/gcc-4.8.5/release/link-static/threading-multi/bzip2.o...


报错2:
error: unrecognized command line option “-m64”

  • 10
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

行者Sun1989

您的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值