How to build an shared library and call it in other ndk program

前端 未结 2 736
情歌与酒
情歌与酒 2020-12-16 14:53

I want to build an shared library. To build it, I need to call another shared library. Here is what I did:

1.Create one Android project,named \"BuildLib\",and add a

相关标签:
2条回答
  • 2020-12-16 14:57

    In your second Android.mk, try replacing the first module with:

    LOCAL_PATH := $(call my-dir)
    include $(CLEAR_VARS)
    LOCAL_SRC_FILES := libadd.so
    LOCAL_MODULE := add_prebuilt
    LOCAL_EXPORT_C_INCLUDES := add.h
    include $(PREBUILD_SHARED_LIBRARY)
    

    The LOCAL_EXPORT_C_INCLUDES flag should attach the header information to the add_prebuilt module, so it can be linked with your final library.

    0 讨论(0)
  • 2020-12-16 15:09

    Just in case anyone needs it:

    A bit hackish way to keep the linker happy:

    LOCAL_LDLIBS := -llog
    

    or

    LOCAL_LDLIBS := -L$(LOCAL_PATH)/lib -lMyStuff
    

    Less hackish:

    LOCAL_PATH := $(call my-dir)
    
    include $(CLEAR_VARS)
    LOCAL_MODULE := xyz
    LOCAL_SRC_FILES += xyz/xyz.c
    LOCAL_LDLIBS := -llog
    include $(BUILD_SHARED_LIBRARY)    # this builds libxyz.so
    
    
    include $(CLEAR_VARS)
    LOCAL_MODULE    := abc
    LOCAL_SHARED_LIBRARIES := xyz    # <=== !!! this makes libabc.so dependent on libxyz.so
    LOCAL_SRC_FILES := abc/abc.c
    #LOCAL_LDLIBS := ...
    include $(BUILD_SHARED_LIBRARY)    # this builds libabc.so
    
    0 讨论(0)
提交回复
热议问题