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

时间:2015-07-27 09:40:38

标签: c++ linux eclipse cross-compiling crypto++

我想交叉编译库crypto ++,以便在运行Debian的beaglebone上进行部署。我的主机PC以64位配置运行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

我的猜测是,由于编译器配置为armhf,它无法识别为amd64编译的库。

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

我尝试过的解决方案

  • 使用libcrypto ++包,其架构指定为armhf,如在multiarch中所做的那样。 armhf库已安装(根据apt),但我无法在其中包含和链接我的代码。
  • 按照此wiki上的说明手动尝试编译库。但是,每当我尝试编译库时,我总会遇到错误。

如何在基于x64的PC上安装armhf架构的libcryptopp库,以便我可以交叉编译?还是有其他方法可以解决这个问题。

修改

正如下面的答案所示,我尝试了建议的方法。我稍微修改了脚本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命令构建库并遇到以下错误

/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时,我可以找到上面提到的所有三个错误文件,即libc.so.6libc_nonshared.ald-linux-armhf.so.3

根据@jww的建议,我将这个问题转移到一个新问题,因为我无法链接。我的结果留待完整。

2 个答案:

答案 0 :(得分:2)

  

如何在基于x64的PC上安装armhf架构的libcryptopp库,以便我可以交叉编译?还是有其他方法可以解决这个问题。

在Crypto ++ wiki上签出ARM Embedded (Command Line)

注意:维基页面有点过时了。您现在可以使用GNUmakefile-cross。我没有更新页面以反映最近的更改,例如GNUmakefile-cross

GNUmakefile-cross是专为在Android,iOS,Windows Phone,ARM嵌入式和裸机上进行交叉编译而设计的特殊用途(我怀疑有人会在以后做,但我将其作为平台进行了测试)。您仍然需要运行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.sh中获取Setenv-embedded.sh.zip

答案 1 :(得分:1)

除了jww's answer之外,我想补充一些其他说明。 (这些说明与2015年11月20日发布的5.6.3版相关。)

可能需要编辑config.h文件以更改某些选项。见Config.h on the Crypto++ wiki。特别是:

    可能需要定义
  • CRYPTOPP_NO_UNALIGNED_DATA_ACCESS,以便代码在无法进行未对齐数据读/写(例如ARM)的系统上正常运行。
  • CRYPTOPP_INIT_PRIORITYCRYPTOPP_USER_PRIORITY可能需要定义。有关详细信息,请参阅Static Initialization Order Fiasco - Crypto++ Wiki
  • CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562可能需要定义或未定义,具体取决于使用它的项目是否使用较旧的API功能。

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