简体   繁体   English

为armhf编译Crypto ++以进行交叉编译

[英]Compiling Crypto++ for armhf for cross compiling

I want to cross compile the library crypto++ for deployment on a beaglebone running Debian. 我想交叉编译库crypto ++,以便在运行Debian的beaglebone上进行部署。 My host PC runs Ubuntu 14.04 LTS in a 64-bit configuration. 我的主机PC在64位配置中运行Ubuntu 14.04 LTS。

I face the following problem when I invoke the make command from eclipse 从eclipse调用make命令时,遇到以下问题

arm-linux-gnueabihf-g++-4.8 -L/usr/include/cryptopp -o "GCMwithAES"  ./main.o   -lcryptopp
/usr/lib/../lib/libcryptopp.so: file not recognized: File format not recognized

My guess is that since the compiler is configured for armhf, it cannot recognize the library that was compiled for amd64. 我的猜测是,由于编译器是为armhf配置的,因此无法识别为amd64编译的库。

I have successfully cross compiled and run standard (ie no external libraries) programs from my host PC to my target device. 我已经成功地将编译的标准程序(即没有外部库)从主机PC交叉运行到目标设备。

Solutions that I have tried 我尝试过的解决方案

  • Used libcrypto++ packages with the architecture specified as armhf as done in multiarch. 使用的libcrypto ++软件包具有指定为armhf的体系结构,如在多体系结构中所做的那样。 The armhf libraries get installed ( as per apt) but I am unable to include and link my code with them. armhf库已安装(按照apt的要求),但是我无法包含它们并将其链接到我的代码。
  • Manually try to compile the library as per the instruction given on this wiki . 按照此Wiki上的说明手动尝试编译库。 However, I always run into errors whenever I try to compile the library. 但是,每次尝试编译库时,我总是遇到错误。

How do I install the libcryptopp libraries of the armhf architecture on my x64 based PC so I can cross compile? 如何在基于x64的PC上安装armhf体系结构的libcryptopp库,以便可以交叉编译? or is there any other way to resolve this issue. 还是有其他方法可以解决此问题。

Edit 编辑

As suggested in the answer below I tried out the method suggested. 如下面的答案所建议,我尝试了建议的方法。 I slightly modified the script setenv-embed.sh since I had gcc-4.8 instead of gcc-4.7 . 我稍微修改了脚本setenv-embed.sh因为我使用的是gcc-4.8而不是gcc-4.7 The results of running the script are 运行脚本的结果是

CPP: /usr/bin/arm-linux-gnueabihf-cpp 
CXX: /usr/bin/arm-linux-gnueabihf-g++
AR: /usr/bin/arm-linux-gnueabihf-ar
LD: /usr/bin/arm-linux-gnueabihf-ld
RANLIB: /usr/bin/arm-linux-gnueabihf-gcc-ranlib-4.8

ARM_EMBEDDED_TOOLCHAIN: /usr/bin
ARM_EMBEDDED_CXX_HEADERS: /usr/arm-linux-gnueabihf/include/c++/4.8.2
ARM_EMBEDDED_FLAGS: -march=armv7-a mfloat-abi=hard -mfpu=neon -I/usr/arm-linux-gnueabihf/include/c++/4.8.2 -I/usr/arm-linux-gnueabihf/include/c++/4.8.2/arm-linux-gnueabihf 
ARM_EMBEDDED_SYSROOT: /usr/arm-linux-gnueabihf

I build the library using the make command and run into the following error 我使用make命令构建库,并遇到以下错误

/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/bin/‌​ld: cannot find /usr/arm-linux-gnueabihf/lib/libc.so.6 inside /usr/arm-linux-gnueabihf
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/bin/‌​ld: cannot find /usr/arm-linux-gnueabihf/lib/libc_nonshared.a inside /usr/arm-linux-gnueabihf        
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/bin/‌​ld: cannot find /usr/arm-linux-gnueabihf/lib/ld-linux-armhf.so.3 inside /usr/arm-linux-gnueabihf

But when I open the location /usr/arm-linux-gnueabihf/lib I can find all the three error files mentioned above ie libc.so.6 , libc_nonshared.a and ld-linux-armhf.so.3 但是当我打开位置/usr/arm-linux-gnueabihf/lib我可以找到上面提到的所有三个错误文件,即libc.so.6libc_nonshared.ald-linux-armhf.so.3

As per the suggestions of @jww, I'm shifting this to a new question since I'm having trouble linking. 根据@jww的建议,由于无法连接,我将其转移到一个新问题。 My results here are left for completeness. 我在这里的结果仅供参考。

How do I install the libcryptopp libraries of the armhf architecture on my x64 based PC so I can cross compile? 如何在基于x64的PC上安装armhf体系结构的libcryptopp库,以便可以交叉编译? or is there any other way to resolve this issue. 还是有其他方法可以解决此问题。

Checkout ARM Embedded (Command Line) on the Crypto++ wiki. 在Crypto ++ Wiki上签出ARM Embedded(命令行)

Note: that wiki page is a bit dated. 注意:该Wiki页面有些陈旧。 You can now use GNUmakefile-cross . 现在,您可以使用 GNUmakefile-cross I have not updated the page to reflect recent changes like GNUmakefile-cross . 我尚未更新页面以反映最近的更改,例如 GNUmakefile-cross

GNUmakefile-cross is a special purpose built for cross-compiling on Android, iOS, Windows Phone, ARM Embedded, and bare metal (I doubt anyone would do the later, but I tested it as a platform). GNUmakefile-cross是专用于在Android,iOS,Windows Phone,ARM Embedded和裸机上进行交叉编译的特殊目的(我怀疑有人会在以后进行编译,但我将其作为平台进行了测试)。 You will still need to run the setenv-embedded.sh script. 您仍然需要运行setenv-embedded.sh脚本。

To fetch the latest sources from GitHub: 要从GitHub获取最新资源:

git clone https://github.com/weidai11/cryptopp.git cryptopp-armhf

The GitHub sources are quite active at the moment. GitHub源码目前非常活跃。 We are preparing for a Crypto++ 5.6.3 release. 我们正在准备Crypto ++ 5.6.3版本。 5.6.3 will include GNUmakefile-cross . 5.6.3将包括GNUmakefile-cross


The complete instructions will look something like (assuming you have the tools installed): 完整说明如下所示(假设您已安装工具):

git clone https://github.com/weidai11/cryptopp.git cryptopp-armhf
cd cryptopp-armhf

# Note the leading dot!!!
. ./setenv-embedded.sh
# The command above must execute successfully
# It cannot display a message like "**CXX is not valid**"

# Build it
make -f GNUmakefile-cross static dynamic cryptest.exe

# Check it
$ find . -name cryptest.exe
./cryptest.exe
$ /usr/bin/arm-linux-gnueabi-readelf -h ./cryptest.exe | grep -i 'class\|machine' 
  Class:                             ELF32
  Machine: 

Because the GitHub sources are quite active at the moment, I've already added all the other files from Crypto++-Mobile.zip and Setenv-embedded.sh.zip to the official Crypto++ sources. 由于GitHub源代码目前处于活跃状态,因此我已经将 Crypto++-Mobile.zipSetenv-embedded.sh.zip中的所有其他文件添加到了官方Crypto ++源代码中。 You only need to get setenv-embedded.sh out of the Setenv-embedded.sh.zip . 您只需 setenv-embedded.sh中获取 Setenv-embedded.sh.zip

In addition to jww's answer , I wanted to add some further notes. 除了jww的答案外 ,我还想补充一些注意事项。 (These notes are relevant for version 5.6.3 released 20-Nov-2015.) (这些说明与2015年11月20日发布的5.6.3版本相关。)

It may be necessary to edit the config.h file to change some options. 可能需要编辑config.h文件以更改某些选项。 See Config.h on the Crypto++ wiki . 请参阅Crypto ++ Wiki上的Config.h In particular: 尤其是:

  • CRYPTOPP_NO_UNALIGNED_DATA_ACCESS may need to be defined so that the code operates properly on systems that can't do unaligned data read/writes (eg ARM). 可能需要定义CRYPTOPP_NO_UNALIGNED_DATA_ACCESS ,以便代码可以在无法执行未对齐数据读写的系统(例如ARM)上正常运行。
  • CRYPTOPP_INIT_PRIORITY and CRYPTOPP_USER_PRIORITY may need to be defined. 可能需要定义CRYPTOPP_INIT_PRIORITYCRYPTOPP_USER_PRIORITY See Static Initialization Order Fiasco - Crypto++ Wiki for details. 有关详细信息 ,请参见静态初始化顺序失败-Crypto ++ Wiki
  • CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 may need to be defined or undefined, depending on whether the project using it is using older API features or not. CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562可能需要定义或不确定,具体取决于使用它的项目是否使用较旧的API功能。

After building the library, it is very much worth running the test program cryptest.exe v on the target system, to check if the library has been built okay for that system. 构建库之后,非常值得在目标系统上运行测试程序cryptest.exe v ,以检查是否已针对该系统构建了库。 For example, by doing this, I discovered that the library doesn't work properly on the ARM-based BeagleBone Black unless I define CRYPTOPP_NO_UNALIGNED_DATA_ACCESS in config.h (it freezes indefinitely on the test step Testing MessageDigest algorithm SHA-384. ). 例如,通过这样做,我发现该库无法在基于ARM的BeagleBone Black上正常工作,除非我在config.h定义了CRYPTOPP_NO_UNALIGNED_DATA_ACCESS (它在测试步骤Testing MessageDigest algorithm SHA-384.上无限期冻结)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM