我在Linux上使用Clang(NDK 15c Clang独立工具链)为Android构建OpenSSL 1.1.0g做了无数次尝试。 背景是Qt 5.10需要OpenSSL 1.1.0,而Clang似乎是Android的推荐C ++编译器(我还使用Clang构建Qt 5.10)。
经过无休止的尝试后,构建OpenSSL的最后一个脚本就是这一个(上次尝试时有一些已经过去的注释行,脚本在OpenSSL目录中):
#/bin/sh
export ANDROIDTC="${HOME}/userapps/android/clang_arm_toolchain_15"
export TCBINARIES="$ANDROIDTC/bin"
export TCINCLUDES="$ANDROIDTC/arm-linux-androideabi"
export TCSYSROOT="$ANDROIDTC/sysroot"
export STDCPPTC="$TCINCLUDES/lib/libstdc++.a"
export PATH="$PATH:$TCBINARIES:$TCINCLUDES/bin"
export AS=${TCBINARIES}/arm-linux-androideabi-clang
export CC=${TCBINARIES}/arm-linux-androideabi-clang
export CXX=${TCBINARIES}/arm-linux-androideabi-clang++
export LD=${TCBINARIES}/arm-linux-androideabi-ld
#export CFLAGS="--sysroot=$TCSYSROOT -DANDROID -Wall -I$TCSYSROOT/usr/include -I$TCSYSROOT -I$TCINCLUDES/include -O3 -fomit-frame-pointer -fPIE"
export CFLAGS="--sysroot=$TCSYSROOT -DANDROID -Wall -I$TCINCLUDES/include -O3 -fomit-frame-pointer -fPIE -std=c++14"
export CXXFLAGS="--sysroot=$TCSYSROOT -DANDROID -Wall -I$TCINCLUDES/include -O3 -fomit-frame-pointer -fPIE"
export LDFLAGS="-L$TCSYSROOT/usr/lib -L$TCINCLUDES/lib -llog -fPIE -pie"
export GDB_CFLAGS="--sysroot=$TCSYSROOT -Wall -g -I$TCINCLUDES/include"
make clean
#./config --host=arm-linux --prefix=$TCINCLUDES --libdir="$TCINCLUDES/lib"
#./Configure --host=arm-linux --prefix=$TCINCLUDES --libdir="$TCINCLUDES/lib" --disable-shared --enable-static android-armeabi
./Configure --prefix=$TCINCLUDES --libdir="$TCINCLUDES/lib" android-armeabi
#./Configure --prefix=$TCINCLUDES --libdir="$TCINCLUDES/lib" --openssldir=. android
#./config --host=x86_64-pc-linux-gnu --prefix=$TCINCLUDES --libdir="$TCINCLUDES/lib" android
#make -j 8
Configure的输出
Configuring for android-armeabi
CC =/<HOME>/userapps/android/clang_arm_toolchain_15/bin/arm-linux-androideabi-clang
CFLAG =-Wall -O3 -pthread -fPIC --sysroot=$(CROSS_SYSROOT) -Wa,--noexecstack
SHARED_CFLAG =-fPIC -DOPENSSL_USE_NODELETE
DEFINES =DSO_DLFCN HAVE_DLFCN_H NDEBUG OPENSSL_THREADS OPENSSL_NO_STATIC_ENGINE OPENSSL_PIC OPENSSL_BN_ASM_MONT OPENSSL_BN_ASM_GF2m SHA1_ASM SHA256_ASM SHA512_ASM AES_ASM BSAES_ASM GHASH_ASM ECP_NISTZ256_ASM POLY1305_ASM
LFLAG =
PLIB_LFLAG =
EX_LIBS =-ldl
APPS_OBJ =
CPUID_OBJ =armcap.o armv4cpuid.o
UPLINK_OBJ =
BN_ASM =bn_asm.o armv4-mont.o armv4-gf2m.o
EC_ASM =ecp_nistz256.o ecp_nistz256-armv4.o
DES_ENC =des_enc.o fcrypt_b.o
AES_ENC =aes_cbc.o aes-armv4.o bsaes-armv7.o aesv8-armx.o
BF_ENC =bf_enc.o
CAST_ENC =c_enc.o
RC4_ENC =rc4_enc.o rc4_skey.o
RC5_ENC =rc5_enc.o
MD5_OBJ_ASM =
SHA1_OBJ_ASM =sha1-armv4-large.o sha256-armv4.o sha512-armv4.o
RMD160_OBJ_ASM=
CMLL_ENC =camellia.o cmll_misc.o cmll_cbc.o
MODES_OBJ =ghash-armv4.o ghashv8-armx.o
PADLOCK_OBJ =
CHACHA_ENC =chacha-armv4.o
POLY1305_OBJ =poly1305-armv4.o
BLAKE2_OBJ =
PROCESSOR =
RANLIB =ranlib
ARFLAGS =
PERL =/usr/bin/perl
THIRTY_TWO_BIT mode
BN_LLONG mode
RC4 uses unsigned char
Configured for android-armeabi.
“make”的输出是:
/usr/include/linux/errno.h:1::
In file included from /usr/include/bits/errno.h:24:
/usr/include/linux/errno.h:1:10: 10: fatal error: fatal error: 'asm/errno.h' file not found
#include <asm/errno.h>
^~~~~~~~~~~~~
'asm/errno.h' file not found
这种情况下的问题似乎是找不到sysroot目录。 (其他尝试部分导致其他错误。)
有人知道如何构建吗?
谢谢。
答案 0 :(得分:1)
您需要告诉Configure
目标架构asm
标头的位置。许多架构都有单独的包含目录。看起来您可能正在使用独立的工具链,因此此路径可能不完全正确,但在我的系统上,缺少的标题位于:
$ANDROID_NDK_ROOT/sysroot/usr/include/arm-linux-androideabi
您已将-I$TCINCLUDES/include
添加到旗帜中。您需要做的就是添加-I$TCINCLUDES/include/arm-linux-androideabi
。