【问题标题】:Cross compiling c program with openssl for Android使用openssl for Android交叉编译c程序
【发布时间】:2015-01-26 21:57:27
【问题描述】:

我在尝试使用 openssl for android x-86 编译 c 程序时遇到以下问题。我使用以下脚本设置环境变量如下:

setenv-android.sh

运行脚本后,我有以下环境。

./setenv-android_x86.sh 
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory
Error: FIPS_SIG does not specify incore module. Please edit this script.
ANDROID_NDK_ROOT: /opt/android-ndk-r9d-x86
ANDROID_ARCH: arch-x86
ANDROID_EABI: x86-4.6
ANDROID_API: android-18
ANDROID_SYSROOT: /opt/android-ndk-r9d-x86/platforms/android-18/arch-x86
ANDROID_TOOLCHAIN: /opt/android-ndk-r9d-x86/toolchains/x86-4.6/prebuilt/darwin-x86_64/bin
FIPS_SIG: 
CROSS_COMPILE: i686-linux-android-
ANDROID_DEV: /opt/android-ndk-r9d-x86/platforms/android-18/arch-x86/usr

但是,当尝试使用以下命令进行编译时,出现以下错误:

密码 /opt/android-ndk-r9d-x86/bin

./i686-linux-android-gcc Test.c -o test -lcrypto 

fatal error: openssl/conf.h: No such file or directory

当我找到 openssl/conf.h 时,我发现该文件在很多地方都可用:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/openssl/conf.h /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/openssl/conf.h /data/local/arm/ssl/include/openssl/conf.h /data/local/ssl/include/openssl/conf.h /openssl/include/openssl/conf.h /openssl-1.0.1e/include/openssl/conf.h /openssl-1.0.1g/include/openssl/conf.h /opt/local/include/openssl/conf.h /usr/include/openssl/conf.h /usr/local/include/openssl/conf.h /usr/local/ssl/android-14/include/openssl/conf.h /usr/local/ssl/android-18/include/openssl/conf.h
/usr/local/ssl/android-18-x86/include/openssl/conf.h /usr/local/ssl/include/openssl/conf.h

我认为正确的路径是:
/usr/local/ssl/android-18-x86/include/openssl/conf.h
我尝试使用 -L 选项,但没有运气。
-L/usr/local/ssl/android-18-x86/include/

谁能解释一下如何正确设置路径来解决这个问题。 (最后C代码没有问题,因为它可以用gcc正确编译)

【问题讨论】:

  • 你试过“-I/usr/local/ssl/android-18-x86/include/”吗? -L 用于将目录添加到库搜索路径,-I(大写 i)用于将目录添加到包含搜索路径。
  • 我现在试过了,-我没有工作。虽然它给出了比以前更多的错误......

标签: android c macos ssl


【解决方案1】:

您正在使用 Android NDK 编译您的代码,它通过将您需要为 android 编译的所有内容放入 ${ANDROID_SYSROOT} 目录来创建一个“虚拟”编译环境。

您列出的那些目录在 sysroot 之外,因此对构建系统不可用,因此会出现错误。您必须安装 OpenSSL for Android 并将生成的标头和二进制文件放在那里。你可以关注这个guide 来帮助你。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-21
    • 1970-01-01
    • 1970-01-01
    • 2013-12-09
    相关资源
    最近更新 更多