Communication issue when creating static and shared libraries using Android NDK

I have a program that I am porting that links several libraries together when creating an executable file. I built all these libraries using a standalone toolchain and using a standalone toolchain, I can create an executable that works on an Android device. So, it seems that the libraries I created are functional. Now I am trying to include these libraries in the application. So in my android.mk I have something like this:

LOCAL_PATH := $(call my-dir) ROOT_PATH := $(LOCAL_PATH) include $(call all-subdir-makefiles) include $(CLEAR_VARS) LOCAL_PATH = $(ROOT_PATH) LOCAL_MODULE := test-libs LOCAL_STATIC_LIBRARIES := staticA LOCAL_SHARED_LIBRARIES := sharedA sharedB sharedC sharedD LOCAL_SRC_FILES := test-libs.c include $(BUILD_SHARED_LIBRARY) 

For each of the libraries I have Android.mk, like this

 LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := sharedA LOCAL_SRC_FILES := libsharedA.so include $(PREBUILT_SHARED_LIBRARY) 

The static library and one of the shared libraries do not have any dependencies, and if I just turn them on, everything will be cool. One common pre-created library depends only on the static collection library, and the rest depends on the pre-created static library and other ready-made shared libraries.

The problem is that I load everything that depends on the static library through System.loadLibrary (). I get a useful message:

 Unable to dlopen(libsharedA.so) Cannot load library: link_image 

Delving into this and following the suggestions given here on how to use strace:

http://mpigulski.blogspot.com/2010/09/debugging-dlopen-unsatisfiedlinkerror.html

I found that when loading shared libraries, they cannot find the function that is in my static library.

So, how to properly use the pre-built shared library, the use of which depends on the pre-created static library and does not have this problem?

+4
source share
1 answer

Shared libraries should not be dependent on static libraries.

Static libraries are intended to be linked (at compile time) with the executable file, and not to be added at run time.

If your shared library A uses the static library B, either create a shared version of B or enable B when you link A together.

+4
source

Source: https://habr.com/ru/post/1402344/


All Articles