简体   繁体   English

在Linux上使用Clang(NDK 15c独立工具链)为Android构建OpenSSL 1.1.0g

[英]Building OpenSSL 1.1.0g for Android with Clang (NDK 15c standalone toolchain) on Linux

I made numerous successless attempts to build OpenSSL 1.1.0g for Android with Clang (NDK 15c Clang standalone toolchain) on Linux. 我进行了许多成功的尝试,以在Linux上使用Clang(NDK 15c Clang独立工具链)为Android构建OpenSSL 1.1.0g。 The background is that Qt 5.10 needs OpenSSL 1.1.0 and Clang seems to be the recommended C++ compiler for Android (I also build Qt 5.10 with Clang). 背景是Qt 5.10需要OpenSSL 1.1.0,而Clang似乎是Android推荐的C ++编译器(我也使用Clang构建Qt 5.10)。

After endless attempts my last script to build OpenSSL was this one (there are some outcommented lines from the last attempts, the script is in the OpenSSL directory): 经过无休止的尝试后,我构建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

The output of Configure is 配置的输出是

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.

The output of "make" is: “ 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

The problem in this case seems to be that the sysroot directory was not found. 在这种情况下的问题似乎是找不到sysroot目录。 (Other attempts partially resulted in other errors.) (其他尝试会部分导致其他错误。)

Does anybody know how to build it? 有人知道怎么建吗?

Thank you. 谢谢。

You need to tell Configure where the asm headers are for the target architecture. 您需要告诉Configure目标asm标头在哪里。 There are separate include directories for many architectures. 对于许多体系结构,都有单独的包含目录。 It looks like you might be using a standalone toolchain, so this path might not be completely correct for you, but on my system the missing header is located at: 看来您可能正在使用独立的工具链,所以该路径可能对您而言并不完全正确,但是在我的系统上,缺少的标头位于:

$ANDROID_NDK_ROOT/sysroot/usr/include/arm-linux-androideabi

You're already adding -I$TCINCLUDES/include to your flags. 您已经在标记中添加了-I$TCINCLUDES/include All you should need to do is also add -I$TCINCLUDES/include/arm-linux-androideabi . 您还需要添加-I$TCINCLUDES/include/arm-linux-androideabi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM