android编译 cryptopp_编译用于交叉编译的armhf的Crypto ++

在Ubuntu 14.04 LTS 64位主机上尝试为运行Debian的Beaglebone Black交叉编译Crypto++库时遇到问题。错误提示表明arm-linux-gnueabihf-g++无法识别为amd64编译的库。尝试使用multiarch指定armhf架构的libcrypto++包和手动编译库,但均未成功。现在的问题是如何在x64系统上安装armhf架构的libcryptopp库以便进行交叉编译,或者寻求其他解决方案。
摘要由CSDN通过智能技术生成

I want to cross compile the library crypto++ for deployment on a beaglebone running Debian. My host PC runs Ubuntu 14.04 LTS in a 64-bit configuration.

I face the following problem when I invoke the make command from eclipse

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.

I have successfully cross compiled and run standard (ie no external libraries) programs from my host PC to my target device.

Solutions that I have tried

Used libcrypto++ packages with the architecture specified as armhf as done in multiarch. The armhf libraries get installed ( as per apt) but I am unable to include and link my code with them.

Manually try to compile the library as per the instruction given on this 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? 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. 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

/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

As per the suggestions of @jww, I'm shifting this to a new question since I'm having trouble linking. 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? or is there any other way to resolve this issue.

Checkout ARM Embedded (Command Line) on the Crypto++ wiki.

Note: that wiki page is a bit dated. You can now use GNUmakefile-cross. I have not updated the page to reflect recent changes like 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). You will still need to run the setenv-embedded.sh script.

To fetch the latest sources from GitHub:

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

The GitHub sources are quite active at the moment. We are preparing for a Crypto++ 5.6.3 release. 5.6.3 will include

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. You only need to get setenv-embedded.sh out of the Setenv-embedded.sh.zip.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以按照以下步骤在Windows下编译Crypto++: 1. 下载Crypto++源代码。你可以从官网(https://www.cryptopp.com/)或Github(https://github.com/weidai11/cryptopp)上下载最新版本的源代码。 2. 解压源代码压缩包到一个目录中。 3. 打开Visual Studio,创建一个新的空项目。 4. 将Crypto++源代码目录中的“cryptlib.h”和“config.h”文件添加到你的项目中。 5. 在Visual Studio中打开项目属性,选择“C/C++” -> “常规” -> “附加包含目录”,将Crypto++源代码目录添加到附加包含目录中。 6. 在项目中添加你要编译Crypto++源代码文件,例如AES加密的源代码文件“aes.cpp”和“rijndael.cpp”。 7. 在Visual Studio中打开“属性管理器”,选择“Microsoft.Cpp.Win32.user”属性表(如果你的项目是32位的)或“Microsoft.Cpp.x64.user”属性表(如果你的项目是64位的)。 8. 在“属性管理器”中选择“VC++目录” -> “包含目录”,添加Crypto++源代码目录。 9. 在“属性管理器”中选择“VC++目录” -> “库目录”,添加Crypto++源代码目录中的“Win32”(如果你的项目是32位的)或“x64”(如果你的项目是64位的)目录。 10. 在Visual Studio中打开“属性页”,选择“链接器” -> “输入”,添加“cryptlib.lib”到附加依赖项中。 11. 点击“生成” -> “生成解决方案”开始编译。 完成上述步骤后,你就可以在Windows上使用Visual Studio编译Crypto++库了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值