- 目錄結(jié)構(gòu)
- 生成.a靜態(tài)庫(kù)
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)庫(kù)
share.h
# include "static.h"
int test_add( int x, int y);
靜態(tài)庫(kù)的頭文件 ,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)庫(kù)
- 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í)行測(cè)試