Android NDK OpenSSL error cross-compiling

2019-09-14 01:53发布

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.

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

# 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:

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

the cryplib.c line 171 says:

#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

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.

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

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.

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.

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

2条回答
萌系小妹纸
2楼-- · 2019-09-14 02:23

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

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.

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.

查看更多
劳资没心,怎么记你
3楼-- · 2019-09-14 02:23

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

You just have to modify _ANDROID_NDK _ANDROID_ARCH _ANDROID_EABI _ANDROID_API parameters

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

around line 120:

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

around line 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.

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.

查看更多
登录 后发表回答