gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 12:02:01 25 4
gpt4 key购买 nike

我想交叉编译库 crypto++ 以部署在运行 Debian 的 beaglebone 上。我的主机以 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,就像在多架构中所做的那样。安装了 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 的建议,我将其转移到一个新问题,因为我在链接时遇到问题。我在这里的结果是为了完整性。

最佳答案

How do I install the libcryptopp libraries of the armhf architecture on my x64 based PC so I can cross compile? or is there any other way to resolve this issue.

结帐 ARM Embedded (Command Line)在 Crypto++ wiki 上。

注意:那个 wiki 页面有点过时了。您现在可以使用 GNUmakefile-cross .我没有更新页面以反射(reflect)最近的变化,如 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.zip 的所有其他文件。和 Setenv-embedded.sh.zip到官方 Crypto++ 来源。你只需要得到 setenv-embedded.sh来自 Setenv-embedded.sh.zip .

关于c++ - 为 armhf 编译 Crypto++ 以进行交叉编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31649738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com