I’m a newer to Android NDK.
There are 3 files, “first.c, first.h, second.c”
I want to compile to 2 shared libraries (libfirst.so, libsecond.so, the second one using the first one)
bellow is the Android.mk
LOCAL_PATH:= $(call my-dir)
# first lib
include $(CLEAR_VARS)
LOCAL_MODULE := libtwolib-first
LOCAL_SRC_FILES := first.c
include $(BUILD_SHARED_LIBRARY)
# second lib
#
include $(CLEAR_VARS)
LOCAL_MODULE := libtwolib-second
LOCAL_SRC_FILES := second.c
LOCAL_SHARED_LIBRARIES := libtwolib-first
include $(BUILD_SHARED_LIBRARY)
first.h
extern int first(int x, int y);
second.c
jint
Java_com_example_twolibs_TwoLibs_add( JNIEnv* env,
jobject this,
jint x,
jint y )
{
return first(x, y);
}
But when to run this program, the application is forced to shut down.
if first is compiled to static library. then it’s OK. Like the related Android.mk bellow:
LOCAL_PATH:= $(call my-dir)
# first lib, which will be built statically
#
include $(CLEAR_VARS)
LOCAL_MODULE := libtwolib-first
LOCAL_SRC_FILES := first.c
include $(BUILD_STATIC_LIBRARY)
# second lib, which will depend on and include the first one
#
include $(CLEAR_VARS)
LOCAL_MODULE := libtwolib-second
LOCAL_SRC_FILES := second.c
LOCAL_STATIC_LIBRARIES := libtwolib-first
include $(BUILD_SHARED_LIBRARY)
Can anyone help me?
Thanks a lot…
I’m pretty new to this myself, but as far as I know you can only have a single shared library. To use several libraries, link them statically, and then build a single shared one from the static ones.