NDK在哪里寻找图书馆?

时间:2014-11-13 10:51:15

标签: android android-ndk

假设我想用NDK编译一个c ++函数,该函数在其体内调用库中的函数(如STL等)。如何告诉NDK在我的电脑库中的哪个库是这样的,当编译我的c ++函数时,NDK会在调用库中的函数时跳转?

1 个答案:

答案 0 :(得分:1)

您必须在Android.mk文件中指定库。

对于标准库,您只需在Application.mk中指定要使用的库,即:

APP_STL=gnustl_shared

用于GCC标准库。

对于其他库,您必须在Android.mk文件中放入要使用的库,并告诉ndk在必要时构建它们。

对于已经构建的库,请输入

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

对于必须构建的库,请输入

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

然后,在执行此操作后,只需添加以下内容

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

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