问题描述:

Suppose I want to compile with the NDK a c++ function that in its body calls a function in a library (like STL, etc). How to tell the NDK where in my pc is the library so that when compiling my c++ function the NDK will make the jump when the function in the library is called ?

网友答案:

You have to specify your libraries in your Android.mk file.

For the standard library, you only have to specify in your Application.mk which one you want to use, i.e.:

APP_STL=gnustl_shared

for the GCC standard library.

For your other libraries, you have to put in your Android.mk file which library you want to use, and tell the ndk to build them if necessary.

For an already build library, put

include $(CLEAR_VARS)

LOCAL_MODULE=<give a name to the lib you want to link>
LOCAL_EXPORT_C_INCLUDES=<path to your lib include directory>
LOCAL_SRC_FILE=<path to your library binary file>


include $(PREBUILT_SHARED_LIBRARY) #or STATIC if your lib is static

For a library that must be build, put

include $(CLEAR_VARS)

LOCAL_MODULE=<give a name to the lib you want to link>
LOCAL_SRC_FILE=<list all the files necessary to build your lib>
LOCAL_EXPORT_C_INCLUDES=<path to your lib include directory>

include $(BUILD_SHARED_LIBRARY) #or STATIC if you want to build it static

Then, after doing that, just add the following

LOCAL_STATIC_LIBRARIES=<list your static libs **using their LOCAL_MODULE names**>

LOCAL_SHARED_LIBRARIES=<list your shared libs **using their LOCAL_MODULE names**>

and voila!

相关阅读:
Top