【问题标题】:Android NDK OpenSSL error cross-compilingAndroid NDK OpenSSL 交叉编译错误
【发布时间】:2015-04-30 14:12:43
【问题描述】:

我是 NDK 的新手,我正在关注 guide 为 Android 构建 OpenSSL,为此我使用的是 Windows 7 和 Cygwin。

我在尝试构建 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

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

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

cryplib.c 第 171 行说:

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

我不知道如何解决这个错误。

另一个是uid.c:77:10: error: #include expects "FILENAME" or <FILENAME> #include OPENSSL_UNISTD

如果我将 uid.c 中的第 77 行更改为 #include &lt;unistd.h&gt;,我会在 Makefile 中收到错误,所以我不知道是否可以修复它,错误是在依赖 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

另一个问题是我是否可以使用本指南将 OpenSSL 库构建到 64 位架构。 (x86_64、arm64 和 mips64)我没有在这些架构中找到有关 Android 的 OpenSSL 的信息,所有关于它的帖子都很旧,并且这些架构对于 Android 不存在

编辑

我找到了一种方法来部分解决我的问题(不是最好的,但它有效),问题是由于某些路径中的一些错误,因为我试图在 Windows 和一些文件上使用 Cywin(我不知道那些)试图到达一些不存在的路径,因为我在 Windows 上而不是在 Linux 上,所以我只是在虚拟机上安装 Ubuntu 并再次尝试这个guide,我可以编译库并且我有 libcrypto。 a libcrypto.so libssl.a libssl.so 适用于 Android ARM、x86、mips、ARM64 和 x86_64 架构。

但是这些库不适用于 x86_64 和 ARM64,当我尝试使用 android.mk 为 x86_64 或 arm64 eabi 编译 .c 时,由于某些兼容性错误,它无法编译,但如果尝试编译 de相同的 .c 文件与“x86_64”或“arm-64”对于 x86 或 arm eabi 它确实编译,所以它们仍然是 32 位库,这不是答案,因为我需要所有架构的库(至少对于 armv5、armv7、armv8-64、x86、x86_64),这只是一小步。

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

【问题讨论】:

    标签: c windows android-ndk openssl cross-compiling


    【解决方案1】:

    当我尝试 make depend 命令时,我遇到了 2 个错误:

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

    符号链接有问题。使用tar zxvf 再次解压压缩包。然后,验证头文件的长度不是 0。

    另请参阅 OpenSSL 邮件列表中的 Inconsistency between crypto.h and cryptlib.c。还有 How to copy symbolic link file from Linux to Windows and then back to Linux but still keeping it as a symbolic link 在 Stack Overflow 上。

    【讨论】:

      【解决方案2】:

      使用guide 并修改文件setenv-android.sh,您可以轻松为arm、x86 和mips 编译openssl。

      你只需要修改_ANDROID_NDK _ANDROID_ARCH _ANDROID_EABI _ANDROID_API参数

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

      第 120 行附近:

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

      第 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
      

      如果您按照指南进行操作,您将拥有 libcrypto.a、libssl.a、libcrypto.so 和 libssl.so。

      如果您想要 64 位架构的库,您可以使用 adb 从设备中拉取,所有 android 设备在 /system/lib64 中都有 libcrypto.so 和 libssl.so 用于 64 位版本(仅在 64 位设备中),并且/system/lib 32 位版本,你可以使用模拟器,如果你想要这个link 中的静态库(libcrypto.a 和 libssl.a)的 64 位版本,你可以找到方法。

      【讨论】:

      • 您确实应该按预期使用该网站。这是一个问题对一个问题。当您移动问题时,它会创建一堆不相关的答案,这几乎会使问题和旧答案对未来的访问者毫无用处。
      猜你喜欢
      • 2013-12-09
      • 2012-12-28
      • 2013-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-06
      • 2013-05-18
      相关资源
      最近更新 更多