NDK學習三:[轉載] android開發 NDK 編譯和使用靜態庫、動態庫

轉載: http://hi.baidu.com/joec3/blog/item/687cf98913065dae0e244442.htmlhtml

特別注意,編譯靜態庫的時候你須要多加一個Application.mk,俺開始沒有注意,一直不編譯spa

NDK 編譯和使用靜態庫、動態庫htm

狀況一:編譯靜態庫blog

狀況二:編譯動態庫get

狀況三:編譯動態庫+靜態庫it

狀況四:已有第三方靜態庫(動態庫),編譯靜態庫(動態庫)io

默認全部代碼和文件在$project/jni下,不然特殊說明。編譯

狀況一:編譯靜態庫call

文件Android.mk:static

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := hello-jni
LOCAL_SRC_FILES := hello-jni.c
include $(BUILD_STATIC_LIBRARY)

文件Application.mk:

APP_MODULES :=hello-jni


狀況二:編譯動態庫


文件Android.mk:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := hello-jni
LOCAL_SRC_FILES := hello-jni.c
include $(BUILD_SHARED_LIBRARY)

狀況三:編譯動態庫+靜態庫

文件Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE    := mylib_static
LOCAL_SRC_FILES := src.c
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := mylib_shared
LOCAL_SRC_FILES := src2.c

LOCAL_STATIC_LIBRARIES := mylib_static

include $(BUILD_SHARED_LIBRARY)


狀況四:已有第三方靜態庫(動態庫),編譯靜態庫(動態庫)

文件Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := thirdlib1      # name it whatever
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libthird1.a     # or $(so_path)/libthird1.so
#LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)    #or PREBUILT_SHARED_LIBRARY

include $(CLEAR_VARS)
LOCAL_MODULE    := mylib_use_thirdlib
LOCAL_SRC_FILES := src.c

LOCAL_STATIC_LIBRARIES := thirdlib1       #or LOCAL_SHARED_LIBRARY

include $(BUILD_SHARED_LIBRARY)   #若是編譯靜態庫,須要Application.mk

相關文章
相關標籤/搜索