I've seen similar posts but none were giving correct answers.
Setup:
Linux Ubuntu 14.04
Android NDK r8e
Boost 1.53
OpenCV 2.4.9
While compiling I got this warning:
Compile++ thumb : usit <= wahet.cpp
SharedLibrary : libusit.so
/home/tassilo/android-ndks/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: warning: hidden symbol '__aeabi_atexit' in /home/tassilo/android-ndks/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/libgnustl_static.a(atexit_arm.o) is referenced by DSO jni/opencv/sdk/native/jni/../libs/armeabi-v7a/libopencv_java.so
Install : libusit.so => libs/armeabi-v7a/libusit.so
I am not yet trying to call my C++ code, all I am doing is creating the library which results in this error:
09-16 14:34:59.189: V/IRISREC(654): Native code library failed to load.
09-16 14:34:59.189: V/IRISREC(654): java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1936]: 36 could not load needed library 'libopencv_java.so' for 'libusit.so' (load_library[1091]: Library 'libopencv_java.so' not found)
Here is my Android.mk
LOCAL_PATH := $(call my-dir)
NDK_ROOT := /home/tassilo/android-ndks/android-ndk-r8e
include $(CLEAR_VARS)
include ./jni/opencv/sdk/native/jni/OpenCV.mk
LOCAL_MODULE := usit
LOCAL_SRC_FILES := wahet.cpp
LOCAL_C_INCLUDES:= ./jni/opencv/sdk/native/jni/include
LOCAL_CFLAGS += -I$(LOCAL_PATH)/boost/include/boost-1_53
LOCAL_LDLIBS += -L$(LOCAL_PATH)/boost/lib/ -lboost_system-gcc-mt-1_53 -lboost_regex-gcc-mt-1_53 -lboost_filesystem-gcc-mt-1_53 -lboost_date_time-gcc-mt-1_53 \
-L$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi \
-lgnustl_static \
-L$(SYSROOT)/usr/lib -llog
include $(BUILD_SHARED_LIBRARY)
Application.mk
APP_PLATFORM := android-8
APP_ABI := armeabi-v7a
APP_OPTIM := debug
NDK_DEBUG := 1
NDK_TOOLCHAIN_VERSION := 4.6
APP_STL := gnustl_static
APP_CPPFLAGS := -fexceptions -frtti
and the library load in my MainAcitvity.java
static {
try {
System.loadLibrary("usit");
} catch (UnsatisfiedLinkError e) {
Log.v(TAG, "Native code library failed to load.\n" + e);
} catch (Exception e) {
Log.v(TAG, "Exception: " + e);
}
}
So the error is thrown in my first catch block.
The need library files are in my folder
./jni/opencv/sdk/native/libs/ -armeabi/ -armeabi-v7a etc.
I am failing around with all this stuff since several days.. Any help is appreciated.
解决方案
Regarding hidden symbol '__aeabi_atexit', the answer at opencv.org suggests to use gnustl_shared instead of gnustl_static.
This fit my personal experience with opencv_java, and means that the Java code must change accordingly:
static {
try {
System.loadLibrary("gnustl_shared"); // added
System.loadLibrary("opencv_java");
System.loadLibrary("usit");
} catch (UnsatisfiedLinkError e) {
Log.v(TAG, "Native code library failed to load.\n" + e);
} catch (Exception e) {
Log.v(TAG, "Exception: " + e);
}
}
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_INSTALL_MODULES:=on
include ./jni/opencv/sdk/native/jni/OpenCV.mk
LOCAL_MODULE := usit
LOCAL_SRC_FILES := wahet.cpp
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/opencv/sdk/native/jni/include \
$(LOCAL_PATH)/boost/include/boost-1_53
LOCAL_LDLIBS += -L$(LOCAL_PATH)/boost/lib/ \
-lboost_system-gcc-mt-1_53 \
-lboost_regex-gcc-mt-1_53 \
-lboost_filesystem-gcc-mt-1_53 \
-lboost_date_time-gcc-mt-1_53 \
-llog
include $(BUILD_SHARED_LIBRARY)
Application.mk
APP_PLATFORM := android-8
APP_ABI := armeabi-v7a
APP_OPTIM := debug
NDK_DEBUG := 1
NDK_TOOLCHAIN_VERSION := 4.6
APP_STL := gnustl_shared
APP_CPPFLAGS := -fexceptions -frtti