【问题标题】:Build Android-openssl library for platform 2.1为平台 2.1 构建 Android-openssl 库
【发布时间】:2012-01-12 18:58:42
【问题描述】:

我正在使用https://github.com/eighthave/openssl-android 提供的 open-ssl 源代码 构建一个可以在android项目中使用的库。

根据 README.txt 中给出的说明,我能够为 Android 平台版本 2.2(级别 -8)编译它

但我的应用要求它兼容 2.1(级别 -7)。

我使用 default.properties 文件 (https://github.com/eighthave/openssl-android/blob/master/default.properties) 尝试了以下选项

1) 设置目标=android-7

2) 设置目标=android-5

但是当我使用命令 ndk-build 编译它时,它会给出以下错误

    Compile thumb  : crypto <= dsa_vrf.c
    Compile thumb  : crypto <= dso_dl.c
    Compile thumb  : crypto <= dso_dlfcn.c
    /Crypto/openssl-android/crypto/dso/dso_dlfcn.c: In function 'dlfcn_pathbyaddr':
    /Crypto/openssl-android/crypto/dso/dso_dlfcn.c:445: error: 'Dl_info' undeclared (first    use in this function)
    /Crypto/openssl-android/crypto/dso/dso_dlfcn.c:445: error: (Each undeclared identifier   is reported only once
    /Crypto/openssl-android/crypto/dso/dso_dlfcn.c:445: error: for each function it appears in.)
    /Crypto/openssl-android/crypto/dso/dso_dlfcn.c:445: error: expected ';' before 'dli'
    /Crypto/openssl-android/crypto/dso/dso_dlfcn.c:455: error: 'dli' undeclared (first use in this function)
    make: *** [obj/local/armeabi/objs/crypto/dso/dso_dlfcn.o] Error 1

根据错误消息 - Dl_info 未定义。但是如果我们转到文件 dso_dlfcn.c ,则已经提供了结构的定义。 (https://github.com/eighthave/openssl-android/blob/master/crypto/dso/dso_dlfcn.c)

并且此代码在默认属性文件中为 target=android-8 编译,但不适用于 android-7 或 android-5。

请求您帮助我解决此错误。并让我知道需要进行哪些更改才能为 android 2.1 平台编译它。

提前致谢。

【问题讨论】:

标签: android java-native-interface openssl android-ndk shared-libraries


【解决方案1】:

尝试在 dso_dlfcn.c 中包含以下代码:

typedef struct {
const char *dli_fname;  /* Pathname of shared object that
                           contains address */
void       *dli_fbase;  /* Address at which shared object
                           is loaded */
const char *dli_sname;  /* Name of nearest symbol with address
                           lower than addr */
void       *dli_saddr;  /* Exact address of symbol named
                           in dli_sname */
} Dl_info;
int dladdr(const void *addr, Dl_info *info) { return 0; }

之前:

#ifdef __linux
# ifndef _GNU_SOURCE
#  define _GNU_SOURCE   /* make sure dladdr is declared */
# endif
#endif

在我的例子中,库构建完成。

【讨论】:

  • 谢谢,库构建成功。
  • 这个问题依然存在..!!但是@Yuri 建议的解决方法救了我.. 谢谢:)
  • 一点也不!祝实验顺利:)
【解决方案2】:

尝试安装最新的 NDK 版本并适当更新 Application.mk 文件。

LOCAL_PATH := $(call my-dir)
APP_PLATFORM := android-19
NDK_TOOLCHAIN_VERSION := clang
APP_ABI := armeabi-v7a
APP_STL := gnustl_static
APP_CPPFLAGS += -frtti 
APP_CPPFLAGS += -fexceptions
APP_CPPFLAGS += -DANDROID
APP_PROJECT_PATH := $(shell pwd)
APP_BUILD_SCRIPT := $(LOCAL_PATH)/../Android.mk

以上2个问题就解决了。

【讨论】:

    【解决方案3】:

    我对@Yuri 的解决方案有一个问题,不得不稍微改进一下。我的APP_ABIApplication.mk 中设置为all。就我而言,这意味着在armeabiarmeabi-v7a 中,我也在为x86mips 构建。我还在 android sdk 中安装了android-9 目标,以便在其他项目中使用。 ndk 从android-9 开始支持x86mips。正如文档中所写,当ndk-build 开始构建这些目标时,它会自动切换到android-9 目标。什么? - 是的,它将无法编译:-)。这是我的解决方案:

    1. 在crypto/Android.mk 中找到local_c_flags := -DNO_WINDOWS_BRAINDEATH 行。在行后写这个http://pastebin.com/7euUVD7A
    2. Yuri 的代码必须插入if definedhttp://pastebin.com/V58gTSBU
    3. 顺便说一句,我在#include &lt;openssl/dso.h&gt; 之后插入了尤里的块,但在#ifdef __linux 之前没有

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-01
      相关资源
      最近更新 更多