Android下的so库实例

创建文件夹mkdir test,并创建三个文件main.c,max.c,Android.mk

main.c

#include <stdio.h>
extern int max(int,int);
int main()
{
    int a=5,b=3;
    int c;
    c=max(a,b);
    printf("the max number is %d\n",c);
    return 0;
}

max.c

int max(int x,int y)
{
    return x>y?x:y;
}

Android.mk

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)
LOCAL_SRC_FILES := max.c
LOCAL_PRELINK_MODULE := false
LOCAL_MODULE := libmax
include $(BUILD_SHARED_LIBRARY)//生成共享库

include $(CLEAR_VARS)
LOCAL_SRC_FILES := main.c
LOCAL_CFLAGS = -lmax
LOCAL_SHARED_LIBRARIES := libmax
LOCAL_MODULE := mainc
include $(BUILD_EXECUTABLE)//生成可执行文件

mmm -B test

将libmax.so丢到/system/lib下,mainc丢到/system/bin下,运行mainc结果正确,说明该.so文件被调用了。

你可能感兴趣的:(Android下的so库实例)