ndk 編譯和使用靜態庫、動態庫
情況一:編譯靜態庫
情況二:編譯動態庫
情況三:編譯動態庫+靜態庫
情況四:已有第三方靜態庫(動態庫),編譯靜態庫(動態庫)
預設所有**和檔案在$project/jni下,否則特殊說明。
情況一:編譯靜態庫
檔案android.mk:
local_path := $(call my-dir)
include $(clear_vars)
local_module
:= hello-jni
local_src_files := hello-jni.c
include $(build_static_library)
情況二:編譯動態庫
檔案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)
#orprebuilt_shared_library
include $(clear_vars)
local_module
:= mylib_use_thirdlib
local_src_files := src.c
local_static_libraries:= thirdlib1
#orlocal_shared_library
include $(build_shared_library)
NDK 靜態庫和動態庫原理以及編譯流程
完成巨集替換 檔案引入 以及去除空行 注釋等,為下一步的編譯做準備。也就是對各種預處理命令進行處理,包括標頭檔案的包含 巨集定義的擴充套件 條件編譯的選擇等。經過預處理後,檔案會變大很多。test.c 檔案記憶體 include int main 通過以下命令進行預處理 gcc e test.c o...
編譯靜態庫編譯動態庫
編譯靜態庫 cr標誌告訴ar將object檔案封裝 archive 我們可以使用nm s 命令來檢視.a檔案的內容 ar cr libmyhello.a hello.o 或 cvr 編譯動態庫 gcc c fpic test1.c gcc c fpic test2.c fpic告訴gcc將源 編譯成...
gcc編譯使用靜態庫 動態庫
假設已經有可用的liboutprint.a和liboutprint.so.1.0.0可用,則 gcc o hello static l.loutprint hello.cpp gcc o hello l.loutprint hello.cpp export ld library path pwd n...