以下内容均来自个人笔记并重新梳理,如有错误欢迎指正!
如果对您有帮助,烦请点赞、关注、转发!如果您有其他想要了解的,欢迎私信联系我~
背景介绍
近期,笔者同事在进行业务容器适配 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”