rana
rana

Reputation: 1862

Openssl Build Issue with Android NDK r8

I am trying to build Openssl inside my NDK app . I am constantly getting linking error even after following all necessary steps expected by Android ndk build. I am using ndk-build command with ndk supported library. i could see libcrypto.So bieng compiled and linked successfully

Compile thumb  : crypto <= sha512-armv4.S
SharedLibrary  : libcrypto.so
Install        : libcrypto.so => /Users/<me>/Downloads/paddybyers-openssl-android-2b40b8b/libs/armeabi/libcrypto.so

but openssl which starts after this is failing for some reason .I tried on all possible ways including building on eclipse as well as on command line.I even tried to build the openssl seperately as a stand alone project. But it always stops at the same level.

Using mac OS x NDK r8 Openssl source from : https://github.com/eighthave/openssl-android.git (I tried building on guardproject https://github.com/guardianproject/openssl-android.git )

it is throwing an error before it starts compiling openssl after creating libcrypto.So

****Compile thumb  : ssl <= ssl_algs.c
Compile thumb  : ssl <= bio_ssl.c
Compile thumb  : ssl <= ssl_err.c
Compile thumb  : ssl <= kssl.c
SharedLibrary  : libssl.so
Executable     : openssl
/Users/me/Documents/android/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6.x-google/../../../../arm-linux-androideabi/bin/ld: warning: libz.so, needed by ./obj/local/armeabi/libcrypto.so, not found (try using -rpath or -rpath-link)
./obj/local/armeabi/libcrypto.so: undefined reference to `zError'
./obj/local/armeabi/libcrypto.so: undefined reference to `inflateEnd'
./obj/local/armeabi/libcrypto.so: undefined reference to `deflate'
./obj/local/armeabi/libcrypto.so: undefined reference to `deflateInit_'
./obj/local/armeabi/libcrypto.so: undefined reference to `inflate'
./obj/local/armeabi/libcrypto.so: undefined reference to `deflateEnd'
./obj/local/armeabi/libcrypto.so: undefined reference to `inflateInit_'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/openssl] Error 1**** }

I would really appreciate if some one help me out on this ?

Upvotes: 3

Views: 6850

Answers (5)

Naseef Chowdhury
Naseef Chowdhury

Reputation: 2464

I was also facing same problem with android ndk r8e. Then I have downloaded openssl-static-android form git. That worked like charm. And the version of openssl you are using is successfully build in android ndk r7e. And one more thing, if you want to link this .so files to another library file or to make .apk, I will suggest you to use .a files instead of .so. Because .so files sometimes causes linker problem. If you are intended to use .a files you can use openssl-static-android from git. It works fine with all the versions of ndk.

N.B: If you are using android ndk r8e, I suggest you should check the binary files to check whether it is cleaned or not. Because there is a bug in android ndk r8e.

Upvotes: 0

AlvinX
AlvinX

Reputation: 29

Try adding the following line in your OpenSSL1.0.1cForAndroid\jni\Application.mk

NDK_TOOLCHAIN_VERSION=4.4.3

I just fixed the same problem by doing this.

Upvotes: 2

minsk
minsk

Reputation: 885

I ran into the same issue and fixed it by modifying OpenSSL1.0.1cForAndroid/crypto/Android.mk, adding libzib to the export list:

crypto/Android.mk
LOCAL_EXPORT_LDLIBS := -lz 

Crypto/Android.mk does have "LOCAL_LDLIBS += -lz" and so it successfully links it when building libcrypto but apparently it's not enough to propagate it to when linking in ssl (?).

I'm using ndk r8b, gcc 4.6

Upvotes: 4

NuSkooler
NuSkooler

Reputation: 5525

Looks like you need to link against zlib as well (or disable zlib support in OpenSSL). You can do this with -lz (It's part of Android)

Upvotes: 0

user827992
user827992

Reputation: 1753

Most likely you have a linking related issue, try to read the answer to this question

How to link any library in ndk application

Upvotes: 0

Related Questions