Android MK導(dǎo)入第三方靜態(tài)庫.a編譯成執(zhí)行文件,或者SO

  • 目錄結(jié)構(gòu)
image.png
  • 生成.a靜態(tài)庫

static.h

int add( int x, int y);

static.cpp

#include "include/static.h"
int add( int x, int y)
{
     return x + y;
}

  • Android mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := static_add
LOCAL_SRC_FILES := static.cpp
include $(BUILD_STATIC_LIBRARY)

  • 使用靜調(diào)庫
image.png

share.h

# include "static.h"
int test_add( int x, int y);

靜態(tài)庫的頭文件 ,static.h

share.cpp


# include "include/share.h"
# include "include/static.h"
# include "log/log.h"

int test_add( int x, int y)
{
     // 調(diào)用static里面的方法
     return add(x, y);
}



int main() {
      test_add(5,6);
 ALOGE("test_addtest_addtest_addtest_addtest_addtest_add");
    return 0;

}

static_add.a 編譯好的靜態(tài)庫

  • Android mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := static_add
LOCAL_SRC_FILES := libstatic_add.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := share_add
LOCAL_STATIC_LIBRARIES := static_add
LOCAL_SHARED_LIBRARIES := liblog
LOCAL_SRC_FILES := share.cpp
include $(BUILD_EXECUTABLE)

最后編譯,會(huì)在system/bin 下生成一個(gè)可執(zhí)行的二進(jìn)制文件share_add,拷貝到手機(jī)即可執(zhí)行測試

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容