Android NDK links shared libraries libxxx.so.ver instead of libxxx.so - android

I've compiled my own shared library which depends on external shared libraries (ffmpeg and x264) using ndk-build. I've defined external libraries as it is described in documentation:
LOCAL_PATH := $(my-root-dir)/external_libs
include $(CLEAR_VARS)
LOCAL_MODULE := avcodec
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/lib/libavcodec.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := avutil
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/lib/libavutil.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := swscale
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/lib/libswscale.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := x264
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/lib/libx264.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_SHARED_LIBRARY)
and have installed external shared libraries for all needed ABIs:
external_libs
- armeabi
- - include
- - lib
- - - libavcodec.so -> libavcodec.so.57.24.101
- - - libavcodec.so.57 -> libavcodec.so.57.24.101
- - - libavcodec.so.57.24.101
- - - libavutil.so -> libavutil.so.55.16.101
- - - libavutil.so.55 -> libavutil.so.55.16.101
- - - libavutil.so.55.16.101
- - - libswresample.so -> libswresample.so.2.0.101
- - - libswresample.so.2 -> libswresample.so.2.0.101
- - - libswresample.so.2.0.101
- - - libswscale.so -> libswscale.so.4.0.100
- - - libswscale.so.4 -> libswscale.so.4.0.100
- - - libswscale.so.4.0.100
- - - libx264.so -> libx264.so.148
- - - libx264.so.148
- armeabi-v7a
- - include
- - lib
- - - libavcodec.so -> libavcodec.so.57.24.101
- - - libavcodec.so.57 -> libavcodec.so.57.24.101
- - - libavcodec.so.57.24.101
- - - libavutil.so -> libavutil.so.55.16.101
- - - libavutil.so.55 -> libavutil.so.55.16.101
- - - libavutil.so.55.16.101
... (etc)
In my library's Android.mk I've added reference to this external libraries:
LOCAL_SHARED_LIBRARIES += libx264
Project has builded just fine, external libraries have been copied to the lib/$(TARGET_ARCH_ABI):
lib
- armeabi
- - libavcodec.so
- - libavutil.so
- - libswscale.so
- - libx264.so
- armeabi-v7a
- - libavcodec.so
- - libavutil.so
- - libswscale.so
- - libx264.so
and than to device/simulator. But when I load my library in application with System.loadLibrary("mylibrary"); I get error:
java.lang.UnsatisfiedLinkError: dlopen failed: library "libx264.so.148" not found
at java.lang.Runtime.loadLibrary(Runtime.java:372)
When I inspect my library with
arm-linux-androideabi-readelf -d libs/armeabi-v7a/libmylibrary.so
I get this:
Dynamic section at offset 0x12d34c contains 42 entries:
Tag Type Name/Value
0x00000003 (PLTGOT) 0x12eb00
0x00000002 (PLTRELSZ) 2536 (bytes)
0x00000017 (JMPREL) 0x3a264
0x00000014 (PLTREL) REL
0x00000011 (REL) 0x352ac
0x00000012 (RELSZ) 20408 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x6ffffffa (RELCOUNT) 2546
0x00000006 (SYMTAB) 0x148
0x0000000b (SYMENT) 16 (bytes)
0x00000005 (STRTAB) 0x10c58
0x0000000a (STRSZ) 106907 (bytes)
0x00000004 (HASH) 0x2adf4
0x00000001 (NEEDED) Shared library: [libx264.so.148]
0x00000001 (NEEDED) Shared library: [libavcodec.so.57]
0x00000001 (NEEDED) Shared library: [libswscale.so.4]
0x00000001 (NEEDED) Shared library: [libavutil.so.55]
0x00000001 (NEEDED) Shared library: [liblog.so]
0x00000001 (NEEDED) Shared library: [libdl.so]
0x00000001 (NEEDED) Shared library: [libstdc++.so]
0x00000001 (NEEDED) Shared library: [libm.so]
0x00000001 (NEEDED) Shared library: [libc.so]
0x0000000e (SONAME) Library soname: [libmylibrary.so]
0x0000001a (FINI_ARRAY) 0x12d77c
0x0000001c (FINI_ARRAYSZ) 8 (bytes)
0x00000019 (INIT_ARRAY) 0x12e344
0x0000001b (INIT_ARRAYSZ) 8 (bytes)
0x00000016 (TEXTREL) 0x0
0x00000010 (SYMBOLIC) 0x0
0x0000001e (FLAGS) SYMBOLIC TEXTREL BIND_NOW
0x6ffffffb (FLAGS_1) Flags: NOW
0x6ffffff0 (VERSYM) 0x330cc
0x6ffffffc (VERDEF) 0x35230
0x6ffffffd (VERDEFNUM) 1
0x6ffffffe (VERNEED) 0x3524c
0x6fffffff (VERNEEDNUM) 3
0x00000000 (NULL) 0x0
Why are there references in my libmylibrary.so to libx264.so.148, libavcodec.so.57, etc and not to libx264.so, libavcodec.so, etc as expected?

The linker looks at the soname of libraries, not the file names. You can ask ./configure to generate sonames without version suffix

Related

Reduce opencv4 dynamic lib .so size

I'm trying to reduce .so file size for an android app, but when I recompile the dynamic library my app crashes with this code
java.lang.UnsatisfiedLinkError: No implementation found for long org.opencv.core.Mat.n_Mat() (tried Java_org_opencv_core_Mat_n_1Mat and Java_org_opencv_core_Mat_n_1Mat__).
I'm also tried to recompile from src, but for some reason, when I add modify the root CMakeLists.txt file (line 153 at this time), the compilation fails because doesn't find a file from samples.
Here is my command to recompile .so from static libraries for arm64
$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ -fpic --sysroot=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -target aarch64-linux-android21 -shared -Xlinker -soname=libopencv_java4.so -o libopencv_java4.so -Xlinker --no-as-needed -Xlinker --whole-archive -Xlinker libcpufeatures.a -Xlinker libIlmImf.a -Xlinker liblibjasper.a -Xlinker liblibjpeg-turbo.a -Xlinker liblibpng.a -Xlinker liblibprotobuf.a -Xlinker liblibtiff.a -Xlinker liblibwebp.a -Xlinker libquirc.a -Xlinker libtbb.a -Xlinker libtegra_hal.a -Xlinker libopencv_imgcodecs.a -Xlinker libopencv_imgproc.a -Xlinker libopencv_core.a -Xlinker --no-whole-archive -nostdlib++ -llog -ljnigraphics -landroid -lmediandk -lz
generated .so info
Dynamic section at offset 0x9fabc8 contains 33 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [liblog.so]
0x0000000000000001 (NEEDED) Shared library: [libjnigraphics.so]
0x0000000000000001 (NEEDED) Shared library: [libandroid.so]
0x0000000000000001 (NEEDED) Shared library: [libmediandk.so]
0x0000000000000001 (NEEDED) Shared library: [libz.so]
0x0000000000000001 (NEEDED) Shared library: [libm.so]
0x0000000000000001 (NEEDED) Shared library: [libdl.so]
0x0000000000000001 (NEEDED) Shared library: [libc.so]
0x000000000000000e (SONAME) Library soname: [libopencv_java4.so]
0x0000000000000019 (INIT_ARRAY) 0x9e4948
0x000000000000001b (INIT_ARRAYSZ) 216 (bytes)
0x000000000000001a (FINI_ARRAY) 0x9e4a20
0x000000000000001c (FINI_ARRAYSZ) 16 (bytes)
0x0000000000000004 (HASH) 0x1c8
0x000000006ffffef5 (GNU_HASH) 0x5378
0x0000000000000005 (STRTAB) 0x1d230
0x0000000000000006 (SYMTAB) 0xa8d0
0x000000000000000a (STRSZ) 121597 (bytes)
0x000000000000000b (SYMENT) 24 (bytes)
0x0000000000000003 (PLTGOT) 0xa0ae18
0x0000000000000002 (PLTRELSZ) 27888 (bytes)
0x0000000000000014 (PLTREL) RELA
0x0000000000000017 (JMPREL) 0xb0260
0x0000000000000007 (RELA) 0x3c658
0x0000000000000008 (RELASZ) 474120 (bytes)
0x0000000000000009 (RELAENT) 24 (bytes)
0x000000000000001e (FLAGS) BIND_NOW
0x000000006ffffffb (FLAGS_1) Flags: NOW
0x000000006ffffffe (VERNEED) 0x3c5f8
0x000000006fffffff (VERNEEDNUM) 3
0x000000006ffffff0 (VERSYM) 0x3ad2e
0x000000006ffffff9 (RELACOUNT) 16950
0x0000000000000000 (NULL) 0x0
original .so info
Dynamic section at offset 0x116d898 contains 32 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libdl.so]
0x0000000000000001 (NEEDED) Shared library: [libm.so]
0x0000000000000001 (NEEDED) Shared library: [liblog.so]
0x0000000000000001 (NEEDED) Shared library: [libjnigraphics.so]
0x0000000000000001 (NEEDED) Shared library: [libz.so]
0x0000000000000001 (NEEDED) Shared library: [libc.so]
0x0000000000000001 (NEEDED) Shared library: [libandroid.so]
0x0000000000000001 (NEEDED) Shared library: [libmediandk.so]
0x000000000000000e (SONAME) Library soname: [libopencv_java4.so]
0x0000000000000019 (INIT_ARRAY) 0x11378f0
0x000000000000001b (INIT_ARRAYSZ) 384 (bytes)
0x000000000000001a (FINI_ARRAY) 0x1137a70
0x000000000000001c (FINI_ARRAYSZ) 16 (bytes)
0x0000000000000004 (HASH) 0x228
0x0000000000000005 (STRTAB) 0x3b328
0x0000000000000006 (SYMTAB) 0xc018
0x000000000000000a (STRSZ) 372415 (bytes)
0x000000000000000b (SYMENT) 24 (bytes)
0x0000000000000003 (PLTGOT) 0x117dad8
0x0000000000000002 (PLTRELSZ) 49488 (bytes)
0x0000000000000014 (PLTREL) RELA
0x0000000000000017 (JMPREL) 0x161668
0x0000000000000007 (RELA) 0x9a138
0x0000000000000008 (RELASZ) 816432 (bytes)
0x0000000000000009 (RELAENT) 24 (bytes)
0x000000000000001e (FLAGS) BIND_NOW
0x000000006ffffffb (FLAGS_1) Flags: NOW
0x000000006ffffffe (VERNEED) 0x9a0d8
0x000000006fffffff (VERNEEDNUM) 3
0x000000006ffffff0 (VERSYM) 0x961e8
0x000000006ffffff9 (RELACOUNT) 26157
0x0000000000000000 (NULL) 0x0
Ok, finally I reduced the size of opencv via build_sdk.py script, just added BUILD_LIST="core,imgproc,imgcodecs,java", to the cmake_vars dictionary in build_library function, also I'm disabled the INSTALL_ANDROID_EXAMPLES to "OFF", and passed the --no_samples_build flag as command line option

java.lang.unsatisfiedLinkError lib not found :(failed to link mylib.so)

i've successfully cross compiled a c++ library to the android plateform using the android ndk standalone toolchain.
i've created a new android application project into Eclipse with a jni dolder and Android.mk file and when i do an ndk-build the building goes well and it adds mylib.so to libs/armeabi folder
The problem is when i do a System.loadLibrary("mylibname");
i get the following error in the logcat:
Unable to dlopen(/data/data/com.oussama.firsttry/lib/libdash.so): Cannot load library: link_image[1995]: failed to link libdash.so
that cause a java.lang.UnsatisfiedLinkError: my lib not found**.
There must be a library that my lib depends on and the emulator can't load it so i've done a readelf -d mylib.so and here is the result:
Dynamic section at offset 0x1617c4 contains 26 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libm.so]
0x00000001 (NEEDED) Shared library: [libc.so]
0x00000001 (NEEDED) Shared library: [libdl.so]
0x0000000e (SONAME) Library soname: [libdash.so]
0x00000010 (SYMBOLIC) 0x0
0x0000000f (RPATH) Library rpath: [/home/oussama064/libdash/libdash/../../neededLibs]
0x00000019 (INIT_ARRAY) 0x157268
0x0000001b (INIT_ARRAYSZ) 172 (bytes)
0x0000001a (FINI_ARRAY) 0x157314
0x0000001c (FINI_ARRAYSZ) 8 (bytes)
0x00000004 (HASH) 0xf4
0x00000005 (STRTAB) 0x10f58
0x00000006 (SYMTAB) 0x50b8
0x0000000a (STRSZ) 134112 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000003 (PLTGOT) 0x1618b4
0x00000002 (PLTRELSZ) 1096 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0x40dd8
0x00000011 (REL) 0x31b38
0x00000012 (RELSZ) 62112 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x00000018 (BIND_NOW)
0x6ffffffb (FLAGS_1) Flags: NOW
0x6ffffffa (RELCOUNT) 7738
0x00000000 (NULL) 0x0
Here is my Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS) LOCAL_MODULE := libcurl LOCAL_SRC_FILES :=
../../../../neededLibs/libcurl.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS) LOCAL_MODULE := libxml LOCAL_SRC_FILES :=
../../../../neededLibs/libxml2.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS) LOCAL_MODULE := libz LOCAL_SRC_FILES :=
../../../../neededLibs/libz.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS) LOCAL_MODULE := m LOCAL_SRC_FILES :=
libm.so include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS)
LOCAL_MODULE := dl LOCAL_SRC_FILES := libdl.so
include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE
:= c LOCAL_SRC_FILES := libc.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := d LOCAL_SRC_FILES := libdash.so
LOCAL_SHARED_LIBRARIES := c m dl
LOCAL_STATIC_LIBRARIES := libz libxml libcurl include
$(PREBUILT_SHARED_LIBRARY)
i'am really stuck now and i can't figure out what is the missing library
When i do an ndk-build V=1 -B i get the following result:
rm -f /home/oussama064/Android/workspace/FirstTry/libs/armeabi/lib*.so
/home/oussama064/Android/workspace/FirstTry/libs/armeabi-v7a/lib*.so
/home/oussama064/Android/workspace/FirstTry/libs/mips/lib*.so
/home/oussama064/Android/workspace/FirstTry/libs/x86/lib*.so
rm -f /home/oussama064/Android/workspace/FirstTry/libs/armeabi/gdbserver
/home/oussama064/Android/workspace/FirstTry/libs/armeabi-v7a/gdbserver
/home/oussama064/Android/workspace/FirstTry/libs/mips/gdbserver
/home/oussama064/Android/workspace/FirstTry/libs/x86/gdbserver
rm -f /home/oussama064/Android/workspace/FirstTry/libs/armeabi/gdb.setup
/home/oussama064/Android/workspace/FirstTry/libs/armeabi-v7a/gdb.setup
/home/oussama064/Android/workspace/FirstTry/libs/mips/gdb.setup
/home/oussama064/Android/workspace/FirstTry/libs/x86/gdb.setup
make: Circular obj/local/armeabi/libm.so <- obj/local/armeabi/libm.so dependency
dropped.
make: Circular obj/local/armeabi/libm.so <- obj/local/armeabi/libc.so dependency
dropped.
make: Circular obj/local/armeabi/libdl.so <- obj/local/armeabi/libm.so dependency
dropped.
make: Circular obj/local/armeabi/libdl.so <- obj/local/armeabi/libc.so dependency
dropped.
make: Circular obj/local/armeabi/libdl.so <- obj/local/armeabi/libdl.so dependency
dropped.
Prebuilt : libdl.so <= /home/oussama064/Android/workspace/FirstTry/jni/
cp -f /home/oussama064/Android/workspace/FirstTry/jni/libdl.so
obj/local/armeabi/libdl.so
Prebuilt : libm.so <= /home/oussama064/Android/workspace/FirstTry/jni/
cp -f /home/oussama064/Android/workspace/FirstTry/jni/libm.so obj/local/armeabi/libm.so
make: Circular obj/local/armeabi/libc.so <- obj/local/armeabi/libc.so dependency dropped.
Prebuilt : libc.so <= /home/oussama064/Android/workspace/FirstTry/jni/
cp -f /home/oussama064/Android/workspace/FirstTry/jni/libc.so obj/local/armeabi/libc.so
Install : libc.so =>
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libc.so
install -p ./obj/local/armeabi/libc.so
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libc.so
/home/oussama064/NDK/android-ndk-r8d/toolchains/arm-linux-androideabi-
4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libc.so
Prebuilt : libxml2.a <=
/home/oussama064/Android/workspace/FirstTry/jni/../../../../neededLibs/
cp -f
/home/oussama064/Android/workspace/FirstTry/jni/../../../../neededLibs/libxml2.a
obj/local/armeabi/libxml2.a
Prebuilt : libcurl.a <=
/home/oussama064/Android/workspace/FirstTry/jni/../../../../neededLibs/
cp -f
/home/oussama064/Android/workspace/FirstTry/jni/../../../../neededLibs/libcurl.a
obj/local/armeabi/libcurl.a
Prebuilt : libdash.so <= /home/oussama064/Android/workspace/FirstTry/jni/
cp -f /home/oussama064/Android/workspace/FirstTry/jni/libdash.so
obj/local/armeabi/libdash.so
Install : libdash.so =>
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdash.so
install -p ./obj/local/armeabi/libdash.so
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdash.so
/home/oussama064/NDK/android-ndk-r8d/toolchains/arm-linux-androideabi-
4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdash.so
Install : libdl.so =>
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdl.so
install -p ./obj/local/armeabi/libdl.so
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdl.so
/home/oussama064/NDK/android-ndk-r8d/toolchains/arm-linux-androideabi-
4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdl.so
Install : libm.so =>
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libm.so
install -p ./obj/local/armeabi/libm.so
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libm.so
/home/oussama064/NDK/android-ndk-r8d/toolchains/arm-linux-androideabi-
4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libm.so
I would be thankfull if any one can help me.
You should use the system versions of libm, libc and libdl shared libraries,
LOCAL_LDLIBS := -lm -ldl
If you can't, link them statically.

Cross Compiling GSL for Android

Cross Compiling GSL for Android
I am attempting to cross compile the GNU Scientific Library (GSL) for Android 4.1 using Autotools. My build and host are as follows:
build="i386-apple-darwin10.8.0"
host="arm-linux-androideabi"
Autotools versions:
GNU Automake version 1.11.3
GNU Autoconf version 2.68
GNU Libtool version 2.4.2
My goal is to compile an executable that I can run from a shell on an emulated device. Thus far, I have compiled GSL and my executable using a toolchain that I generated using the Android Native Development Kit (NDK). I then pushed the shared libraries 'libgsl.so.0' and 'libgslcblas.so.0'(both of which are listed in the dynamic section of my executable) to '/system/lib' and the executable to the device.
Here is the the output of arm-linux-androideabi-readelf -d issm.exe
Dynamic section at offset 0x26a2a4 contains 26 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libgsl.so.0]
0x00000001 (NEEDED) Shared library: [libgslcblas.so.0]
0x00000001 (NEEDED) Shared library: [libm.so]
0x00000001 (NEEDED) Shared library: [libc.so]
0x00000001 (NEEDED) Shared library: [libdl.so]
0x0000000f (RPATH) Library rpath: [/Users/gperez/issm/issm-uci/trunk-jpl/externalpackages/gsl/install/lib]
0x00000020 (PREINIT_ARRAY) 0x26d000
0x00000021 (PREINIT_ARRAYSZ) 0x8
0x00000019 (INIT_ARRAY) 0x26d008
0x0000001b (INIT_ARRAYSZ) 1100 (bytes)
0x0000001a (FINI_ARRAY) 0x26d454
0x0000001c (FINI_ARRAYSZ) 8 (bytes)
0x00000004 (HASH) 0x8128
0x00000005 (STRTAB) 0x96a0
0x00000006 (SYMTAB) 0x87f0
0x0000000a (STRSZ) 3588 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000015 (DEBUG) 0x0
0x00000003 (PLTGOT) 0x27239c
0x00000002 (PLTRELSZ) 960 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0xa7ec
0x00000011 (REL) 0xa4a4
0x00000012 (RELSZ) 840 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x00000000 (NULL) 0x0
I realize that the RPATH is incorrect, but if I understand the dynamic linker correctly, then it should fail to find the needed libraries in RPATH and then proceed to check LD_LIBRARY_PATH, where all the libs are situated.
I then proceeded to run my executable, but I was surprised to find the following linking error:
link_image[1936]: 468 could not load needed library 'libgsl.so.0' for './issm.exe' (reloc_library[1285]: 468 cannot locate 'cblas_ctrmv'...
)CANNOT LINK EXECUTABLE
This error lead me to check the contents of 'libgsl.so.0' which are as follows:
Relocation section '.rel.plt' at offset 0x36014 contains 161 entries:
Offset Info Type Sym.Value Sym. Name
00201c54 00002316 R_ARM_JUMP_SLOT 00000000 cblas_ctrmv
00201c58 00002f16 R_ARM_JUMP_SLOT 00000000 cblas_zswap
00201c5c 00003816 R_ARM_JUMP_SLOT 00000000 cblas_zsymm
00201c60 00005016 R_ARM_JUMP_SLOT 00000000 cblas_cgeru
00201c64 00009216 R_ARM_JUMP_SLOT 00000000 cblas_sgemm
00201c68 00009c16 R_ARM_JUMP_SLOT 00000000 cblas_ctrsv
00201c6c 0000c316 R_ARM_JUMP_SLOT 00000000 cblas_sgemv
...
The corresponding '.dynsym' of 'libgslcblas.so.0':
Symbol table '.dynsym' contains 233 entries:
Num: Value Size Type Bind Vis Ndx Name
...
218: 0004e148 64 FUNC GLOBAL DEFAULT 7 __aeabi_f2d
219: 00050314 0 NOTYPE GLOBAL DEFAULT 12 __data_start
220: 0000d69c 1604 FUNC GLOBAL DEFAULT 7 cblas_dgbmv
221: 0002e008 3540 FUNC GLOBAL DEFAULT 7 cblas_ctrmv
222: 00042c34 4184 FUNC GLOBAL DEFAULT 7 cblas_ztbmv
223: 0004de4c 688 FUNC GLOBAL DEFAULT 7 __subdf3
224: 00003dc4 284 FUNC GLOBAL DEFAULT 7 cblas_snrm2
...
Since the very first entry in the Relocation section '.rel.plet' causes the linking to fail, the problem is likely to be with all 'cblas' symbols. I then decided to look at the the Dynamic section of 'libgsl.so.0'
Dynamic section at offset 0x200b60 contains 25 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libm.so]
0x00000001 (NEEDED) Shared library: [libc.so]
0x00000001 (NEEDED) Shared library: [libdl.so]
0x0000000e (SONAME) Library soname: [libgsl.so.0]
0x00000010 (SYMBOLIC) 0x0
0x0000000f (RPATH) Library rpath: [:/Users/gperez/issm/issm-uci/trunk-jpl/externalpackages/gsl/install/lib]
0x00000019 (INIT_ARRAY) 0x200c68
0x0000001b (INIT_ARRAYSZ) 8 (bytes)
0x0000001a (FINI_ARRAY) 0x200c70
0x0000001c (FINI_ARRAYSZ) 12 (bytes)
0x00000004 (HASH) 0xb4
0x00000005 (STRTAB) 0x19b1c
0x00000006 (SYMTAB) 0x860c
0x0000000a (STRSZ) 107542 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000003 (PLTGOT) 0x201c48
0x00000002 (PLTRELSZ) 1288 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0x36014
0x00000011 (REL) 0x33f34
0x00000012 (RELSZ) 8416 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x00000016 (TEXTREL) 0x0
0x6ffffffa (RELCOUNT) 1051
0x00000000 (NULL) 0x0
Here, I find it very interesting that the library has relocation symbols that refer to 'cblas' entries, but 'libgslcblas.so.0' is not listed in the dynamic section. This feels wrong to me, but I don't have the expertise to say so definitively. Can anyone help?
I am continuing to investigate, but I would really appreciate any suggestions, corrections or input or any sort!
Questions
Should 'libgslcblas.so.0' be in the Dynamic section of 'libgsl.so.0' given that 'libgsl.so.0' makes references in its relocation section to cblas constructs?
Could the improperly set RPATH be at the root of all this?
I would suggest using the AOSP instead of autotools.
The GSL can be integrated into Android, by wrapping the GSL source code into Android make files.
You can then use the modules defined in this Android make files to access the functionality of the GSL.
However this only provides access to Applications compiled in the AOSP.

UnsatisfiedLInkError Linking to FFMPEG with NDK

I compiled FFMPEG for android using bambuser's files. The compile runs fine. No errors.
I also made sure to change the package name in build.sh. However, once I try to link to the files, the phone throws an UnsatisfiedLinkError. This is the Androkd.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
MY_LIB_PATH := ffmpeg-android/build/ffmpeg/armeabi/lib
LOCAL_MODULE := bambuser-libavcore
LOCAL_SRC_FILES := $(MY_LIB_PATH)/libavcore.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := bambuser-libavformat
LOCAL_SRC_FILES := $(MY_LIB_PATH)/libavformat.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := bambuser-libavcodec
LOCAL_SRC_FILES := $(MY_LIB_PATH)/libavcodec.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := bambuser-libavdevice
LOCAL_SRC_FILES := $(MY_LIB_PATH)/libavdevice.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := bambuser-libavfilter
LOCAL_SRC_FILES := $(MY_LIB_PATH)/libavfilter.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := bambuser-libavutil
LOCAL_SRC_FILES := $(MY_LIB_PATH)/libavutil.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := bambuser-libswscale
LOCAL_SRC_FILES := $(MY_LIB_PATH)/libswscale.so
include $(PREBUILT_SHARED_LIBRARY)
#local_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libtest_jni
LOCAL_SRC_FILES := libtest/video.c
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/include \
$(LOCAL_PATH)/ffmpeg-android/ffmpeg
LOCAL_LDLIBS := -L$(NDK_PLATFORMS_ROOT)/$(TARGET_PLATFORM)/arch-arm/usr/lib -L$(LOCAL_PATH) -L$(LOCAL_PATH)/ffmpeg-android/build/ffmpeg/armeabi/lib/ -lavformat -lavcodec -lavdevice -lavfilter -lavutil -lswscale -llog -lz -lm
#dl -lgcc
include $(BUILD_SHARED_LIBRARY)
Video.c is dead simple:
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <jni.h>
#include <string.h>
#include <stdio.h>
#include <android/log.h>
void Java_com_bukabros_videolivewallpaper_Opengl2Renderer_loadNthFrame3
(JNIEnv * env, jobject this, jstring fileName) {
jboolean isCopy;
const char * szLogThis = (*env)->GetStringUTFChars(env, fileName, &isCopy);
__android_log_print(ANDROID_LOG_DEBUG, "NDK: ", "NDK:LC: [%s]", szLogThis);
}
Tne corresponding Java code is also simple:
private native void loadNthFrame3(String fileName);
static {
System.loadLibrary("libtest_jni");
}
But I get this error:
E/AndroidRuntime(11489): FATAL EXCEPTION: main
E/AndroidRuntime(11489): java.lang.ExceptionInInitializerError
E/AndroidRuntime(11489): at com.bukabros.videolivewallpaper.VideoLiveWallpaper$CubeEngine.<init>(VideoLiveWallpaper.java:147)
E/AndroidRuntime(11489): at com.bukabros.videolivewallpaper.VideoLiveWallpaper.onCreateEngine(VideoLiveWallpaper.java:120)
E/AndroidRuntime(11489): at android.service.wallpaper.WallpaperService$IWallpaperEngineWrapper.executeMessage(WallpaperService.java:814)
E/AndroidRuntime(11489): at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:61)
E/AndroidRuntime(11489): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(11489): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(11489): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(11489): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(11489): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(11489): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
E/AndroidRuntime(11489): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
E/AndroidRuntime(11489): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(11489): Caused by: java.lang.UnsatisfiedLinkError: Library libtest_jni not found
E/AndroidRuntime(11489): at java.lang.Runtime.loadLibrary(Runtime.java:461)
E/AndroidRuntime(11489): at java.lang.System.loadLibrary(System.java:557)
E/AndroidRuntime(11489): at com.bukabros.videolivewallpaper.Opengl2Renderer.<clinit>(Opengl2Renderer.java:389)
E/AndroidRuntime(11489): ... 12 more
I tried manually loading the prebuilt shared libraries (the bambuser files) in Java (using System.loadLibrary) but then it tells me that the files are not found.
If it helps, here's the output of readelf:
0x00000001 (NEEDED) Shared library: [libc.so]
0x00000001 (NEEDED) Shared library: [libstdc++.so]
0x00000001 (NEEDED) Shared library: [libm.so]
0x00000001 (NEEDED) Shared library: [/data/data/com.bukabros.videolivewallpaper/lib/libavformat.so]
0x00000001 (NEEDED) Shared library: [/data/data/com.bukabros.videolivewallpaper/lib/libavcodec.so]
0x00000001 (NEEDED) Shared library: [/data/data/com.bukabros.videolivewallpaper/lib/libavdevice.so]
0x00000001 (NEEDED) Shared library: [/data/data/com.bukabros.videolivewallpaper/lib/libavfilter.so]
0x00000001 (NEEDED) Shared library: [/data/data/com.bukabros.videolivewallpaper/lib/libavutil.so]
0x00000001 (NEEDED) Shared library: [/data/data/com.bukabros.videolivewallpaper/lib/libswscale.so]
0x00000001 (NEEDED) Shared library: [liblog.so]
0x00000001 (NEEDED) Shared library: [libz.so]
0x00000001 (NEEDED) Shared library: [libdl.so]
0x0000000e (SONAME) Library soname: [libtest_jni.so]
0x00000010 (SYMBOLIC) 0x0
0x00000004 (HASH) 0xd4
0x00000005 (STRTAB) 0x250
0x00000006 (SYMTAB) 0x130
0x0000000a (STRSZ) 712 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000003 (PLTGOT) 0x174c
0x00000002 (PLTRELSZ) 32 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0x55c
0x6ffffffe (VERNEED) 0x53c
0x6fffffff (VERNEEDNUM) 1
0x6ffffff0 (VERSYM) 0x518
0x00000000 (NULL) 0x0
Oh yeah. I'm using ndk r5.
Looks like I found the answer. The problem is that when you load the library in Java (System.loadLibrary), you can NOT use the "lib" prefix. I also had to manually load the ffmpeg libraries in Java. The moral of the story is that you should always read the docs and don't give up:-) Here's the correct code:
static {
System.loadLibrary("avcore");
System.loadLibrary("avformat");
System.loadLibrary("avcodec");
System.loadLibrary("avdevice");
System.loadLibrary("avfilter");
System.loadLibrary("avutil");
System.loadLibrary("swscale");
System.loadLibrary("test_jni");
}

Cross-compiling for Android

I'm trying to cross-compile dropbear for android. The files appear to compile find, but when executed give "program : not found." I did a find and the libraries marked NEEDED appear to be located in the cross-compile environment. I have compiled other programs with this toolchain.
arm-none-linux-gnueabi-readelf -d dropbear
Dynamic section at offset 0x1c158 contains 27 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libutil.so.1]
0x00000001 (NEEDED) Shared library: [libcrypt.so.1]
0x00000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x00000001 (NEEDED) Shared library: [libc.so.6]
0x0000000c (INIT) 0x9428
0x0000000d (FINI) 0x1e1b4
0x00000019 (INIT_ARRAY) 0x2c14c
0x0000001b (INIT_ARRAYSZ) 4 (bytes)
0x0000001a (FINI_ARRAY) 0x2c150
0x0000001c (FINI_ARRAYSZ) 4 (bytes)
0x00000004 (HASH) 0x8168
0x00000005 (STRTAB) 0x8ba0
0x00000006 (SYMTAB) 0x84b0
0x0000000a (STRSZ) 970 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000015 (DEBUG) 0x0
0x00000003 (PLTGOT) 0x2c258
0x00000002 (PLTRELSZ) 848 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0x90d8
0x00000011 (REL) 0x90c8
0x00000012 (RELSZ) 16 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x6ffffffe (VERNEED) 0x9048
0x6fffffff (VERNEEDNUM) 4
0x6ffffff0 (VERSYM) 0x8f6a
0x00000000 (NULL) 0x0
Did you apply the "patch" to dropbear, because dropbear uses /etc/passwd and that does not exist on android.
Found this on Installing Dropbear - MyWiki
Dropbear needs to be patched to work with Android. Android does not use a ‘/etc/passwd’ file, so that needs to be patched together with some directory changes. This also adds a statically password. This password is located at the bottom of ‘debug.h’ in the dropbear directory. The default password is “password”. The patch can be found here: http://pastebin.com/f3dedc5e7
I know dropbear can compile and run on android because CyanogenMOD, along with most of the other ROMs I have used have it on the system.
I found the problem. I was compiling w/o the STATIC=1 flag. Thanks for the reply! Thanks for the reply! I got the patched source from cyanogen's github

Categories

Resources