Re: unsatisfied linkerror when loading a shared library

855 views
Skip to first unread message

RichardC

unread,
Jul 15, 2012, 9:18:12 AM7/15/12
to andro...@googlegroups.com
You need to load them in order with the most dependent library first.

So if libA.so uses libB.so call:
  System.loadlibrary(B)
  System.loadlibrary(A)

There is no automatic cascade load of dependent libs.


On Sunday, July 15, 2012 8:59:02 AM UTC+1, abhiram chitangal wrote:
Hello,

I am trying to use my own build of openssl with my application. Right now I have two shared libraries in my
PROJECT/libs folder.
a) libfipswrapper.so
b) libcrypto.so

I try loading these two through the System.loadlibrary call in my java code and it fails saying that

Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1969]:   130 could not load needed library 'libcrypto.so.1.0.0' for 'libmywrapper.so' (load_library[1111]: Library 'libcrypto.so.1.0.0' not found)

I had to rename the libcrypto.so.1.0.0 that came with my openssl build to libcrypto.so , as it wouldn't take the file names that didn't end with .so.
Any Ideas ?
thanks

eric liou

unread,
Jul 15, 2012, 5:08:53 AM7/15/12
to andro...@googlegroups.com
Digging into the implementation of System.loadlibrary, you'll find
that the native library name format is defined by the macro
'OS_SHARED_LIB_FORMAT_STR'.
It is defined in an arch dependent file AndroidConfig.h
For arm, you can find following line in
system/core/include/arch/linux-arm/AndroidConfig.h

#define OS_SHARED_LIB_FORMAT_STR "lib%s.so"


On Sun, Jul 15, 2012 at 3:59 PM, abhiram chitangal
<abhiram.c...@gmail.com> wrote:
>
> Hello,
>
> I am trying to use my own build of openssl with my application. Right now I have two shared libraries in my
> PROJECT/libs folder.
> a) libfipswrapper.so
> b) libcrypto.so
>
> I try loading these two through the System.loadlibrary call in my java code and it fails saying that
>
> Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1969]: 130 could not load needed library 'libcrypto.so.1.0.0' for 'libmywrapper.so' (load_library[1111]: Library 'libcrypto.so.1.0.0' not found)
>
> I had to rename the libcrypto.so.1.0.0 that came with my openssl build to libcrypto.so , as it wouldn't take the file names that didn't end with .so.
> Any Ideas ?
> thanks
>
> --
> You received this message because you are subscribed to the Google Groups "android-ndk" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/RbN2ayQCUTMJ.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

Amit Agrawal

unread,
Jun 12, 2014, 5:13:09 AM6/12/14
to andro...@googlegroups.com
abhiram,

Were you able to resolve situation. How you dealt with version library since android doesn't allow versioned lib.

Regards.

On Sunday, 15 July 2012 22:20:27 UTC+5:30, abhiram wrote:
Thanks Richard I already tried loading the two shared libraries through the System. call. In my situation it seems that it cannot find the specific library libcrypto.so.1.0.0. Which I build as a PREBUILT share library "libcryto.so" as NDK-BUILD wouldn't accept the filename as a valid one if it din't end with .so.

Here the two of my Android.mk files.

This is the main Android.mk

JNI_DIR := $(call my-dir)
LOCAL_PATH:= $(JNI_DIR)
include $(CLEAR_VARS)
# build the libfips
include lib/Android.mk

# Now Build the shared library
LOCAL_PATH:=$(JNI_DIR)
include $(CLEAR_VARS)
LOCAL_MODULE:=mywrapper
LOCAL_SRC_FILES := nativeCode.c
LOCAL_SHARED_LIBRARIES:=fips
LOCAL_C_INCLUDES:=$(JNI_DIR)/../../../fips/openssl-fips-2.0.1/include \
          $(JNI_DIR)/../../../fips/openssl-1.0.1c/include         
LOCAL_LDLIBS:=-llog
include $(BUILD_SHARED_LIBRARY)

Android.mk for libcrypto.

# Makes Shared Library "libcrypto.so"
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:=fips
LOCAL_SRC_FILES:=libcrypto.so
MY_INC := /home/abhiram/fips/openssl-1.0.1c/include/
LOCAL_EXPORT_C_INCLUDES:=$(MY_INC)
include $(PREBUILT_SHARED_LIBRARY)

I hope this gives out a better idea of what I am trying to do.

Thanks
Reply all
Reply to author
Forward
0 new messages