Android源码中添加C可执行程序

在Android源码中添加C/CPP可执行程序一般保存在external目录中

下面是每个文件的内容

①add.c

#include "add.h"                                                                

int add (int a, int b)
{
    return a+b;
}

②add.h

#ifndef __ADD_H__                                                               
#define __ADD_H__

int add(int a, int b); 

#endif

③main.c

#include <stdio.h>                                                              
#include <cutils/log.h>
#include <utils/Log.h>
#include "add.h"

int main (void)
{
    printf("------------------
");
    printf("test c executable app %d
",add(2,3));
    ALOGD("test-c-app value is %d",add(2,3));
    printf("------------------
");
    
    return 0;
}

④Android.mk

LOCAL_PATH := $(call my-dir)                                                    
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := test_c_app
LOCAL_SRC_FILES :=$(call all-subdir-c-files)
LOCAL_SHARED_LIBRARY := liblog 
LOCAL_LDLIBS    := -llog

include $(BUILD_EXECUTABLE)

下面是运行结果

原文地址:https://www.cnblogs.com/CoderTian/p/5935916.html