Android NDK OpenSSL交叉编译错误

时间:2023-01-26 22:06:13

I am new in NDK and I am following this guide to build OpenSSL for Android, I am using Windows 7 and Cygwin for this.

我是NDK的新手,我正在按照这个指南为Android构建OpenSSL,为此我正在使用Windows 7和Cygwin。

I'm having errors when trying to build the OpenSSL library.

在构建OpenSSL库时,我遇到了一些错误。

# From the 'root' directory
$ . ./setenv-android.sh
$ cd openssl-1.0.1g/

$ perl -pi -e 's/install: all install_docs install_sw/install: install_docs install_sw/g' Makefile.org
$ ./config shared no-ssl2 no-ssl3 no-comp no-hw no-engine --openssldir=/usr/local/ssl/$ANDROID_API

$ make depend
$ make all

When I try the make depend command I have 2 errors:

当我尝试make depend命令时,我有两个错误:

cryptlib.c:171:3: error: #error "Inconsistency between crypto.h and cryptlib.c" # error "Inconsistency between crypto.h and cryptlib.c"

cryptlib。c:171:3: error: #error " crypto之间不一致。h和cryptlib。c“# error”是密码之间的不一致。h和cryptlib.c”

the cryplib.c line 171 says:

cryplib。c 171行说:

#if CRYPTO_NUM_LOCKS != 41
# error "Inconsistency between crypto.h and cryptlib.c"
#endif

I don't know how to fix that error.

我不知道如何修正这个错误。

the other one is uid.c:77:10: error: #include expects "FILENAME" or <FILENAME> #include OPENSSL_UNISTD

另一个是uid。错误:#include预期“文件名”或 #include OPENSSL_UNISTD

if I change the line 77 in uid.c to #include <unistd.h> I get an error in the Makefile, so I don't know if it's the way to fix it, the error was in depend Makefile.

如果我改变uid中的第77行。c # include < unistd。h>我在Makefile中得到了一个错误,所以我不知道这是否是修复它的方法,错误在depend Makefile中。

depend:
    @[ -z "$(THIS)" -o -f buildinf.h ] || touch buildinf.h # fake buildinf.h if it does not exist
    @[ -z "$(THIS)" ] || $(MAKEDEPEND) -- $(CFLAG) $(INCLUDE) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
    @[ -z "$(THIS)" -o -s buildinf.h ] || rm buildinf.h
    @[ -z "$(THIS)" ] || (set -e; target=depend; $(RECURSIVE_MAKE) )
    @if [ -z "$(THIS)" ]; then $(MAKE) -f $(TOP)/Makefile reflect THIS=$@; fi

Another question is if I can use this guide to build the OpenSSL library to the 64bit arch. (x86_64, arm64 and mips64) I haven't found information about OpenSSL for Android in those architectures, all post about it are old and those arch didn't exist for Android

另一个问题是,如果我可以使用这个向导将OpenSSL库构建到64位的arch。(x86_64、arm64和mips64)我还没有在这些体系结构中找到关于Android的OpenSSL的信息,所有关于它的帖子都是旧的,而这些arch在Android中并不存在

EDIT

I found a way to solve partially my problem (not the best one but it works), the problem was due some errors in some paths, because I was trying to use Cywin on Windows and some files(I don't which ones) were trying to reach some paths that doesn't exist because I was on Windows and not in Linux, so I just install Ubuntu on a virtual machine and try this guide again, and I could compile libraries and I have libcrypto.a libcrypto.so libssl.a libssl.so for Android ARM, x86, mips, ARM64 and x86_64 Architectures.

我找到了一种方法来解决部分问题(不是最好的,但它的工作原理),这个问题是由于一些错误的路径,因为我试图使用Cywin在Windows和一些文件(我不哪些)正试图达到一些路径不存在,因为我是在Windows和Linux,我只是在虚拟机安装Ubuntu和再次尝试本指南,我可以编译库和libcrypto。libcrypto。所以libssl。libssl。对于Android ARM, x86, mips, ARM64和x86_64架构。

But the libraries doesn't work for x86_64 and ARM64, when I try to compile a .c using the android.mk for x86_64 or arm64 eabi it doesn't compile due some compatibility errors, but if a try to compile de same .c file withe the "x86_64" or "arm-64" for a x86 or arm eabi it does compile, so they are still a 32bit libraries, this is not the answer because I need the libraries for all the architecture (at least for armv5, armv7, armv8-64, x86, x86_64), this is just a small step.

但是当我尝试使用android编译.c时,这些库并不适用于x86_64和ARM64。可x86_64或arm64 eabi不编译由于一些兼容性错误,但如果尝试编译相同de . c文件一同参加“x86_64”或“手臂- 64”x86和arm eabi编译,所以他们仍然是一个32位的库,这不是我所需要的答案,因为图书馆对所有体系结构(至少在armv5 v7,armv8 - 64 x86,x86_64),这只是一小步。

I will be updating to help someone with the same problem and if someone want to help me.

如果有人想帮助我,我将会更新帮助有同样问题的人。

2 个解决方案

#1


0  

When I try the make depend command I have 2 errors:

当我尝试make depend命令时,我有两个错误:

cryptlib.c:171:3: error: #error "Inconsistency between crypto.h and cryptlib.c"
# error "Inconsistency between crypto.h and cryptlib.c"

There's a problem with the symlinks. Unpack the tarball again with tar zxvf. Then, verify the header files are not 0 length.

符号链接有问题。用tar zxvf重新打开tarball。然后,验证头文件不是0长度。

Also see Inconsistency between crypto.h and cryptlib.c on the OpenSSL mailing list. And How to copy symbolic link file from Linux to Windows and then back to Linux but still keeping it as a symbolic link on Stack Overflow.

还可以看到加密之间的不一致。h和cryptlib。c在OpenSSL邮件列表中。以及如何将符号链接文件从Linux复制到Windows,然后再复制回Linux,但仍然将其作为堆栈溢出的符号链接。

#2


0  

Using this guide and modifying the file setenv-android.sh you can easy compile openssl for arm, x86 and mips.

使用本指南并修改文件setenv-android。您可以轻松地为arm、x86和mips编译openssl。

You just have to modify _ANDROID_NDK _ANDROID_ARCH _ANDROID_EABI _ANDROID_API parameters

您只需修改_ANDROID_NDK _ANDROID_ARCH _ANDROID_EABI _ANDROID_API参数

note: for mips you'll have to add some lines in the file around

注意:对于mips,您需要在文件中添加一些行

around line 120:

在第120行:

 arch-mips)   
  ANDROID_TOOLS="mipsel-linux-android-gcc mipsel-linux-android-ranlib mipsel-linux-android-ld"
;;

around line 200:

在第200行:

if [ "$_ANDROID_ARCH" == "arch-mips" ]; then
   export MACHINE=mipsel
   export RELEASE=2.6.37
   export SYSTEM=android
   export ARCH=mips
   export CROSS_COMPILE="mipsel-linux-android-"
fi

if you follow the guide you'll have libcrypto.a, libssl.a, libcrypto.so and libssl.so.

如果您遵循指南,您将获得libcrypto。libssl。libcrypto。所以,libssl.so。

if you want the libraries for 64 bits architecture you can do a pull from a device using adb, all android device have libcrypto.so and libssl.so in /system/lib64 for 64bits version (only in a 64bits device), and /system/lib the 32bits version, you can use an emulator for that, if you can want the 64bits version of the static libraries (libcrypto.a and libssl.a) in this link you can find the way to do it.

如果想要64位架构的库,可以使用adb从设备中提取数据,所有android设备都有libcrypto。所以,libssl。所以在/system/lib64中,64位版本(仅在64位设备中)和/system/lib中,32位版本,如果你想要64位版本的静态库(libcrypto),你可以使用一个仿真器。a和libsls .a)在这个链接中,您可以找到这样做的方法。

#1


0  

When I try the make depend command I have 2 errors:

当我尝试make depend命令时,我有两个错误:

cryptlib.c:171:3: error: #error "Inconsistency between crypto.h and cryptlib.c"
# error "Inconsistency between crypto.h and cryptlib.c"

There's a problem with the symlinks. Unpack the tarball again with tar zxvf. Then, verify the header files are not 0 length.

符号链接有问题。用tar zxvf重新打开tarball。然后,验证头文件不是0长度。

Also see Inconsistency between crypto.h and cryptlib.c on the OpenSSL mailing list. And How to copy symbolic link file from Linux to Windows and then back to Linux but still keeping it as a symbolic link on Stack Overflow.

还可以看到加密之间的不一致。h和cryptlib。c在OpenSSL邮件列表中。以及如何将符号链接文件从Linux复制到Windows,然后再复制回Linux,但仍然将其作为堆栈溢出的符号链接。

#2


0  

Using this guide and modifying the file setenv-android.sh you can easy compile openssl for arm, x86 and mips.

使用本指南并修改文件setenv-android。您可以轻松地为arm、x86和mips编译openssl。

You just have to modify _ANDROID_NDK _ANDROID_ARCH _ANDROID_EABI _ANDROID_API parameters

您只需修改_ANDROID_NDK _ANDROID_ARCH _ANDROID_EABI _ANDROID_API参数

note: for mips you'll have to add some lines in the file around

注意:对于mips,您需要在文件中添加一些行

around line 120:

在第120行:

 arch-mips)   
  ANDROID_TOOLS="mipsel-linux-android-gcc mipsel-linux-android-ranlib mipsel-linux-android-ld"
;;

around line 200:

在第200行:

if [ "$_ANDROID_ARCH" == "arch-mips" ]; then
   export MACHINE=mipsel
   export RELEASE=2.6.37
   export SYSTEM=android
   export ARCH=mips
   export CROSS_COMPILE="mipsel-linux-android-"
fi

if you follow the guide you'll have libcrypto.a, libssl.a, libcrypto.so and libssl.so.

如果您遵循指南,您将获得libcrypto。libssl。libcrypto。所以,libssl.so。

if you want the libraries for 64 bits architecture you can do a pull from a device using adb, all android device have libcrypto.so and libssl.so in /system/lib64 for 64bits version (only in a 64bits device), and /system/lib the 32bits version, you can use an emulator for that, if you can want the 64bits version of the static libraries (libcrypto.a and libssl.a) in this link you can find the way to do it.

如果想要64位架构的库,可以使用adb从设备中提取数据,所有android设备都有libcrypto。所以,libssl。所以在/system/lib64中,64位版本(仅在64位设备中)和/system/lib中,32位版本,如果你想要64位版本的静态库(libcrypto),你可以使用一个仿真器。a和libsls .a)在这个链接中,您可以找到这样做的方法。