NDK之对例子two-libs的学习

two-libs:两个库的使用,first为静态库,second为动态库,并且second库调用first库。

 

Android.mk文件:

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := libtwolib-first
LOCAL_SRC_FILES := first.c
include $(BUILD_STATIC_LIBRARY) //表示编译成静态库
# second lib, which will depend on and include the first one
include $(CLEAR_VARS)
LOCAL_MODULE    := libtwolib-second
LOCAL_SRC_FILES := second.c
#引用外部库,这里是引用上面的 libtwolib-first
LOCAL_STATIC_LIBRARIES := libtwolib-first
include $(BUILD_SHARED_LIBRARY) //表示编译成动态库

first.h文件:这文件需要手动生成

#ifndef FIRST_H //对于ifndef  define endif 的使用可参考:http://dx2006chenlei.blog.sohu.com/81722171.html
#define FIRST_H
extern int first(int  x, int  y); //表示外部引用此头文件就可以间接获得该头文件对于该方法的实现

#endif 

 

first.c文件: 

#include "first.h"
int  first(int  x, int  y)
{
    return x + y;

 

second.c文件:

#include "first.h"
#include <jni.h>
jint
Java_com_example_twolibs_TwoLibs_add( JNIEnv*  env , jobject  this, jint     x,  jint     y )
{
    return first(x, y);
}
posted on 2012-09-05 17:33  lee0oo0  阅读(571)  评论(0编辑  收藏  举报