ubutum 18.04 arm下编译 RocketMQ-Client-CPP 2.1.0

开源库的编译一般都有种种曲折,当然这个RocketMQ-Client-CPP也不会例外。废话少说,最正确的解决方案永远是那么朴实无华,肯定是去看官网的readme,先把内容填上来。

根据编译了两天的经验来看,可以确定arm下最新版本2.2.0是无法编译通过的,主要是因为如下错误信息:尝试了网上这种编译条件,无解,最终放弃了。

/usr/bin/ld: ../../bin/lib/libcrypto.a(sha1-armv8.o): relocation R_AARCH64_PREL64 against symbol `OPENSSL_armcap_P' which may bind externally can not be used when making a shared object; recompile with -fPIC
../../bin/lib/libcrypto.a(sha1-armv8.o): In function `sha1_block_armv8':
(.text+0x1240): dangerous relocation: unsupported relocation
/usr/bin/ld: ../../bin/lib/libcrypto.a(chacha-armv8.o): relocation R_AARCH64_PREL64 against symbol `OPENSSL_armcap_P' which may bind externally can not be used when making a shared object; recompile with -fPIC
../../bin/lib/libcrypto.a(chacha-armv8.o):(.text+0x20): dangerous relocation: unsupported relocation
/usr/bin/ld: ../../bin/lib/libcrypto.a(poly1305-armv8.o): relocation R_AARCH64_ADR_PREL_LO21 against symbol `poly1305_blocks' which may bind externally can not be used when making a shared object; recompile with -fPIC
../../bin/lib/libcrypto.a(poly1305-armv8.o): In function `poly1305_init':
(.text+0x40): dangerous relocation: unsupported relocation
/usr/bin/ld: ../../bin/lib/libcrypto.a(poly1305-armv8.o): relocation R_AARCH64_ADR_PREL_LO21 against symbol `poly1305_emit' which may bind externally can not be used when making a shared object; recompile with -fPIC
(.text+0x48): dangerous relocation: unsupported relocation
/usr/bin/ld: ../../bin/lib/libcrypto.a(poly1305-armv8.o): relocation R_AARCH64_PREL64 against symbol `OPENSSL_armcap_P' which may bind externally can not be used when making a shared object; recompile with -fPIC
../../bin/lib/libcrypto.a(poly1305-armv8.o): In function `poly1305_emit_neon':
(.text+0x9a0): dangerous relocation: unsupported relocation
/usr/bin/ld: ../../bin/lib/libcrypto.a(sha256-armv8.o): relocation R_AARCH64_PREL64 against symbol `OPENSSL_armcap_P' which may bind externally can not be used when making a shared object; recompile with -fPIC
../../bin/lib/libcrypto.a(sha256-armv8.o): In function `sha256_block_data_order':
(.text+0xf88): dangerous relocation: unsupported relocation
/usr/bin/ld: ../../bin/lib/libcrypto.a(sha512-armv8.o): relocation R_AARCH64_PREL64 against symbol `OPENSSL_armcap_P' which may bind externally can not be used when making a shared object; recompile with -fPIC
../../bin/lib/libcrypto.a(sha512-armv8.o): In function `sha512_block_data_order':
(.text+0x1108): dangerous relocation: unsupported relocation
collect2: error: ld returned 1 exit status

 

 最终编译通过的版本为2.1.0,看了一下build.sh脚本,这个版本不需要openssl,很顺利的编译通过了!!!

https://github.com/apache/rocketmq-client-cpp/archive/refs/tags/2.1.0.tar.gz

Linux and Mac OS

note: make sure the following compile tools or libraries have been installed before running the build script build.sh.

  • compile tools:

    • gcc-c++ 4.8.2: c++ compiler while need support C++11
    • cmake 2.8.0: build jsoncpp require it
    • automake 1.11.1: build libevent require it
    • autoconf 2.65: build libevent require it
    • libtool 2.2.6: build libevent require it
    • (以上内容一般都是开发环境安装了的,应该没毛病,如果缺少什么就直接安装即可)
  • libraries:

    • bzip2-devel 1.0.6: boost depend it
    • zlib-devel
    • (以上两个库是编译依赖,没啥好说如果缺少直接安装就可以了
    • apt-get install libbz2-dev
    • (bzip2的开发环境是 libbz2-dev,个人见识比较少,用这个绝对没错)
apt-get install gcc gcc-c++
apt-get install cmake
apt-get install automake 
apt-get install autoconf
apt-get install libtool
apt-get install bzip-devel
apt-get install libzip
apt-get install libzip-devel

The build.sh script will automatically download and build the dependency libraries including libevent, json and boost. It will save libraries under rocketmq-client-cpp folder, and then build both static and shared libraries for rocketmq-client. If the dependent libraries are built failed, you could try to build it manually with sources libevent 2.0.22jsoncpp 0.10.7boost 1.58.0

以上三个库如果在build.sh的时候无法正常安装,最好手动安装,比较偷懒的方式是将三个包下载下来,放到tmp_down_dir目录下,重新编译即可。

If your host is not available to internet to download the three library source files, you can copy the three library source files (release-2.0.22-stable.zip 0.10.7.zip and boost_1_58_0.tar.gz) to rocketmq-client-cpp root dir, then the build.sh will automatically use the three library source files to build rocketmq-client-cpp:

sh build.sh

等待…… 发现make到10%左右又会报同样的错误

1、修改project-cache.jam

boost报错,修改project-cache.jam,修改部分arm,gcc相关的修改为true

tmp_down_dir/boost_1_58_0/bin.v2/project-cache.jam

# Automatically generated by Boost.Build.
# Do not edit.

module config-cache {
  set "32-bit-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "false" ;
  set "64-bit-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "true" ;
  set "arm-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "true" ;
  set "mips1-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "false" ;
  set "power-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "false" ;
  set "sparc-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "false" ;
  set "x86-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "false" ;
  set "combined-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "false" ;
  set "ac-library-zlib-<address-model>64-<link>static-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "missing" ;
  set "iconv (libc)-<address-model>64-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "false" ;
  set "iconv (separate)-<address-model>64-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "false" ;
  set "icu-<address-model>64-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "false" ;
  set "icu (lib64)-<address-model>64-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "false" ;
  set "x86-<address-model>64-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "false" ;
  set "arm-<address-model>64-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "true" ;
  set "mips1-<address-model>64-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "false" ;
  set "power-<address-model>64-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "false" ;
  set "sparc-<address-model>64-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "false" ;
  set "has_icu builds-<address-model>64-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "false" ;
  set "lockfree boost::atomic_flag-<address-model>64-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "false" ;
  set "lockfree boost::atomic_flag-<address-model>64-<architecture>arm-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "true" ;
  set "has_icu builds-<address-model>64-<architecture>arm-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "true" ;
  set "ac-library-zlib-<address-model>64-<architecture>arm-<link>shared-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "%default" "z" "<link>shared" ;
  set "iconv (libc)-<address-model>64-<architecture>arm-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "true" ;
  set "icu-<address-model>64-<architecture>arm-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "true" ;
  set "gcc visibility-<address-model>64-<architecture>arm-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "true" ;
  set "long double support-<address-model>64-<architecture>arm-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "true" ;
  set "ac-library-zlib-<address-model>64-<architecture>arm-<link>static-<target-os>linux-<toolset-gcc:version>7-<toolset>gcc" : "%default" "z" "<link>static" ;

gcc-7: error: unrecognized command line option ‘-m64’

解决办法:

2、修改CMakeLists.txt

修改CMakeLists.txt, 找到如下代码,注释。

image-20211009081914962

再次执行

3、jsoncpp生成后路径可能与要求路径不一致,手动修改一下就可以了。

Finally, both librocketmq.a and librocketmq.so are saved in rocketmq-client-cpp/bin. when using them to build application or library, besides rocketmq you should also link with following libraries -lpthread -lz -ldl -lrt. Here is an example:

g++ -o consumer_example consumer_example.cpp -lrocketmq -lpthread -lz -ldl -lrt

编译的时候加上依赖库,大概率应该就没有什么问题了。

注意:在build.sh中,编译过程中如果不需要编译某个库,只需要将编译完成的库修改为0即可

 47 declare need_build_jsoncpp=0
 48 declare need_build_libevent=0
 49 declare need_build_boost=1
 50 declare enable_asan=0
 51 declare enable_lsan=0
 52 declare verbose=1
 53 declare codecov=0
 54 declare test=0

Good Luck!!

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值