Android - how to download a shared library?

Ive created the simplest EXECUTABLE and SHARED_LIBRARY. SHARED_LIBRARY is not loaded without changing LD_LIBRARY_PATH:

# ./hello ./hello link_image[1995]: failed to link ./hello CANNOT LINK EXECUTABLE # LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH ./hello Hello, world! 

All code below:

first.h

 #ifndef FIRST_H #define FIRST_H extern int first(int x, int y); #endif /* FIRST_H */ 

first.c

 #include "first.h" int first( int x, int y ) { return x + y; } 

hello.c

 #include <stdio.h> #include "first.h" int main( int argc, char **argv ) { printf( "Hello, world!\n" ); first( 1000, 24 ); return 0; } 

Android.mk

 include $(CLEAR_VARS) LOCAL_MODULE := first LOCAL_SRC_FILES := first.c include $(BUILD_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := hello LOCAL_SRC_FILES := hello.c LOCAL_SHARED_LIBRARIES := first LOCAL_LDFLAGS := -Wl,-rpath,. -Wl,-rpath,/data/data/testlib/lib include $(BUILD_EXECUTABLE) 

readelf - all hello

 ... Dynamic section at offset 0xef4 contains 25 entries: Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align INTERP 0x000154 0x00008154 0x00008154 0x00013 0x00013 R 0x1 [Requesting program interpreter: /system/bin/linker] ... Tag Type Name/Value 0x00000001 (NEEDED) Shared library: [libfirst.so] 0x00000001 (NEEDED) Shared library: [libstdc++.so] 0x00000001 (NEEDED) Shared library: [libm.so] 0x00000001 (NEEDED) Shared library: [libc.so] 0x00000001 (NEEDED) Shared library: [libdl.so] 0x0000000f (RPATH) Library rpath: [.:/data/data/testlib/lib] 

RPATH is here, but the linker is not using it for any reason.

The dynamic linker seems to work fine on Android (with LD_LIBRARY_PATH and its no other RPATH)

What am I doing wrong?

Am I missing something obvious?

RPATH has two directories in my example: (.: / Data / data / testlib / lib), one (.) Should be sufficient.

In this example, Java is missing. It is not used and is not needed for the project.

Basically, I'm looking for a standard <standard> way to load shared libraries from "my directory" without changing LD_LIBRARY_PATH (sometimes this is not possible) or using the shell to unpack all the necessary libraries.

+8
android android-ndk shared-libraries
source share
1 answer

Bionic linker-loader (android / bionic / linker / linker.c in the AOSP source, if you want to check) seems to completely ignore RPATH in ELF. It only considers LD_LIBRARY_PATH and the hard-wired array "/ vendor / lib" and "/ system / lib".

This is based on a quick look at the code on the Ice Cream sandwich tree I checked.

This explains the behavior you see.

+13
source share

All Articles