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.
android android-ndk shared-libraries
Same old guy ...
source share