'Not able to compile openssl for android

I am trying to compile openssl for android and facing some issues. I am following the steps given in this link.

I am using NDK version r20 and OpenSSL 1.1.1c and on a linux machine.

I am facing two issues:

(1) I am able to compile libs for “android-arm” architecture but getting the below errors while compiling sample application.

./libcrypto.so: error: undefined reference to ‘sigdelset’
./libcrypto.so: error: undefined reference to ‘sigfillset’
./libcrypto.so: error: undefined reference to ‘tcgetattr’
./libcrypto.so: error: undefined reference to ‘tcsetattr’
apps/ocsp.o:ocsp.c:function ocsp_main: error: undefined reference to ‘signal’
apps/ocsp.o:ocsp.c:function ocsp_main: error: undefined reference to ‘signal’
apps/ocsp.o:ocsp.c:function ocsp_main: error: undefined reference to ‘signal’
apps/ocsp.o:ocsp.c:function ocsp_main: error: undefined reference to ‘signal’
apps/ocsp.o:ocsp.c:function process_responder: error: undefined reference to ‘__FD_SET_chk’
apps/ocsp.o:ocsp.c:function process_responder: error: undefined reference to ‘__FD_SET_chk’
apps/s_client.o:s_client.c:function s_client_main: error: undefined reference to ‘__FD_SET_chk’
apps/s_client.o:s_client.c:function s_client_main: error: undefined reference to ‘__FD_SET_chk’
apps/s_client.o:s_client.c:function s_client_main: error: undefined reference to ‘__FD_ISSET_chk’
apps/s_client.o:s_client.c:function s_client_main: error: undefined reference to ‘__FD_ISSET_chk’
apps/s_client.o:s_client.c:function s_client_main: error: undefined reference to ‘__FD_ISSET_chk’
apps/s_client.o:s_client.c:function s_client_main: error: undefined reference to ‘__FD_ISSET_chk’
apps/speed.o:speed.c:function speed_main: error: undefined reference to ‘atof’
apps/speed.o:speed.c:function speed_main: error: undefined reference to ‘atof’
apps/speed.o:speed.c:function speed_main: error: undefined reference to ‘atof’
apps/speed.o:speed.c:function speed_main: error: undefined reference to ‘atof’
clang: error: linker command failed with exit code 1 (use -v to see invocation)

(2) I am not able to compile for any other architecture. If I change architecture to “android-arm64” (or any other), I am getting the below errors while compiling library.

crypto/aes/aesv8-armx.S:5:1: error: Unknown arch name
.arch armv8-a+crypto
^
crypto/aes/aesv8-armx.S:17:2: error: invalid instruction, did you mean: stc, stm, str, swp, tst?
 stp x29,x30,[sp,#-16]!
 ^
crypto/aes/aesv8-armx.S:18:6: error: operand must be a register in range [r0, r15]
 add x29,sp,#0
 ^
crypto/aes/aesv8-armx.S:19:6: error: operand must be a register in range [r0, r12] or r14
 mov x3,#-1
 ^

I am changing the architecture by changing the “architecture=android-arm” in the “file-launcher-sh”. Do I need to modify any other variables/macros?



Solution 1:[1]

You built openssl for a newer API level than your app, so the library is not compatible with your app. Here's how I build openssl with r20:

$ export ANDROID_NDK=/path/to/ndk
$ export PATH=$ANDROID_NDK/toolchains/llvm/prebuilt/$HOST/bin:$PATH
$ path/to/openssl/Configure android-$ARCH -D__ANDROID_API__=$MINSDKVERSION --prefix=$INSTALLPATH --openssldir=$INSTALLPATH shared
$ make SHLIB_EXT=.so install_sw

Solution 2:[2]

I just had to open new putty for each new architecture.

I think somehow few of the configurations/variables exported for one architecture are not getting updated when I re-run the script with new architecture.

Solution 3:[3]

Add the compiler flag "no-asm" to ./Configure

./Configure no-asm no-shared android-$ARCH -D__ANDROID_API__=$MINSDKVERSION --prefix=$INSTALLPATH --openssldir=$INSTALLPATH shared

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dan Albert
Solution 2 MayurK
Solution 3 Danoli3