Android NDK/JNI: Building a shared library that depends on other shared libraries

后端 未结 3 492
走了就别回头了
走了就别回头了 2021-02-01 06:29

I am writing an android app that wants to make JNI calls into a shared library built in using the NDK. The trick is this shared library calls functions provided by OTHER shared

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-01 07:09

    The -L option gives the linker a directory path in which to look for libraries. The -l option gives the linker a library file name to link in. Library file names must begin with "lib". Your libraries should be named libsupport_lib1.so and libsupport_lib2.so. If you do that, then this is probably what you should do (replacing attempt #1):

    LOCAL_LDLIBS := -L$(SYSROOT)/../usr/lib -llog -lsupport_lib1 -lsupport_lib2
    LOCAL_LDLIBS += -L$(LOCAL_PATH)/lib
    

    The linker will prefix the library name you specify using -l with "lib" and suffix it with ".so". (Why do you have -L$(SYSROOT)/../usr/lib?)

    I believe that attempts #1 and #2 failed because you did not link your libraries into your executable - they are not mentioned in a -l option. By the way, you can verify this yourself. Unzip the .apk file and look in the lib directory and subdirectories. Are your .so files in there?

    Looking at the error:

    but then... dlopen failed: Could not locate symbol func_that_exists_in_libsupport_lib.so referenced by libnative_lib.so
    

    Can you supply the entire message? dlopen() loads and links libraries into the running process.

提交回复
热议问题