编译Crypto ++ for armhf进行交叉编译

我想交叉编译库crypto ++在运行Debian的beaglebone上进行部署。 我的主机在64位configuration下运行Ubuntu 14.04 LTS。

当我从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 

我的猜测是,因为编译器configuration为armhf,所以无法识别为amd64编译的库。

我已经成功地交叉编译并运行标准(即没有外部库)程序从我的主机到我的目标设备。

我已经尝试过的解决scheme

  • 使用的libcrypto ++软件包与在多armhf中完成的指定为armhf的体系结构一起使用。 armhf库被安装(按照apt),但我无法包括和链接我的代码与他们。
  • 按照维基上的说明手动尝试编译库。 但是,每当我尝试编译库时,我总是遇到错误。

如何在基于x64的PC上安装armhf体系结构的libcryptopp库,以便交叉编译? 或者有没有其他办法来解决这个问题。

编辑

正如下面的答案中所build议的,我尝试了build议的方法。 我稍微修改了脚本setenv-embed.sh因为我有gcc-4.8而不是gcc-4.7 。 运行脚本的结果是

 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 

我使用make命令构build库,并运行以下错误

 /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 

但是当我打开位置/usr/arm-linux-gnueabihf/lib我可以find上面提到的所有三个错误文件,即libc.so.6libc_nonshared.ald-linux-armhf.so.3

根据@jww的build议,我将这个问题转移到了一个新的问题上,因为我无法链接。 我在这里的结果是完整的。

如何在基于x64的PC上安装armhf体系结构的libcryptopp库,以便交叉编译? 或者有没有其他办法来解决这个问题。

在Crypto ++ wiki上签出ARM Embedded(命令行) 。

注意:该wiki页面有点过时。 你现在可以使用GNUmakefile-cross 我没有更新页面以反映像GNUmakefile-cross最近更改。

GNUmakefile-cross是一个专门为在Android,iOS,Windows Phone,ARM Embedded和裸机上进行交叉编译而构建的特殊目的(我怀疑后面会有人做,但是我将它作为一个平台进行测试)。 您仍然需要运行setenv-embedded.sh脚本。

从GitHub获取最新的源代码:

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

GitHub的资源目前非常活跃。 我们正在准备一个Crypto ++ 5.6.3版本。 5.6.3将包含GNUmakefile-cross


完整的说明将看起来像(假设你已经安装了这些工具):

 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: 

由于GitHub源码目前非常活跃,我已经将所有其他文件从Crypto++-Mobile.zipSetenv-embedded.sh.zip到官方的Crypto ++源代码中。 您只需要将setenv-embedded.shsetenv-embedded.sh取出Setenv-embedded.sh.zip

除了WWW的回答之外 ,我想补充一些说明。 (这些注释与2015年11月20日发布的5.6.3版本相关。)

可能需要编辑config.h文件来更改某些选项。 请参阅Crypto ++ wiki上的Config.h 。 尤其是:

  • CRYPTOPP_NO_UNALIGNED_DATA_ACCESS可能需要定义,以便代码在不能进行未对齐数据读/写(例如ARM)的系统上正常运行。
  • 可能需要定义CRYPTOPP_INIT_PRIORITYCRYPTOPP_USER_PRIORITY 。 有关详细信息 ,请参阅静态初始化命令Fiasco – Crypto ++ Wiki 。
  • CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562可能需要定义或未定义,取决于使用它的项目是否使用旧API功能。

构建库之后,在目标系统上运行测试程序cryptest.exe v是非常值得的,以检查该库是否已经为该系统构建好。 例如,通过这样做,我发现该库在基于ARM的BeagleBone Black上无法正常工作,除非我在config.h定义了CRYPTOPP_NO_UNALIGNED_DATA_ACCESS (它在测试步骤Testing MessageDigest algorithm SHA-384.上无限期地冻结)。