Mac下ndk交叉编译arm平台程序

1.下载ndk

2.使用ndk交叉编译exp.c

<1>.编写:Makefile
NDK_ROOT=/Users/xxx/Documents/Android_SDK/android-ndk-r12b
TOOLCHAINS_ROOT=$(NDK_ROOT)/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64
TOOLCHAINS_PREFIX=$(TOOLCHAINS_ROOT)/bin/arm-linux-androideabi
TOOLCHAINS_INCLUDE=$(TOOLCHAINS_ROOT)/lib/gcc/arm-linux-androideabi/4.9.x/include-fixed
PLATFORM_ROOT=$(NDK_ROOT)/platforms/android-21/arch-arm
PLATFORM_INCLUDE=$(PLATFORM_ROOT)/usr/include
PLATFORM_LIB=$(PLATFORM_ROOT)/usr/lib

MODULE_NAME=exp
BUILD_TYPE=c
PATH_ANDROID=/data/local/

FLAGS=-I$(TOOLCHAINS_INCLUDE) \
	-I$(PLATFORM_INCLUDE) \
	-L$(PLATFORM_LIB) \
	-nostdlib \
	-lgcc \
	-Bdynamic \
	-lc	\
	-O0

OBJS=$(MODULE_NAME).o \
	$(PLATFORM_LIB)/crtbegin_dynamic.o \
	$(PLATFORM_LIB)/crtend_android.o

all:
	$(TOOLCHAINS_PREFIX)-gcc $(FLAGS) -c $(MODULE_NAME).$(BUILD_TYPE) -o $(MODULE_NAME).o
	$(TOOLCHAINS_PREFIX)-gcc $(FLAGS) -S $(MODULE_NAME).$(BUILD_TYPE) -o $(MODULE_NAME).S
	$(TOOLCHAINS_PREFIX)-gcc $(FLAGS) $(OBJS) -o $(MODULE_NAME)
clean:
	$(RM) *.o $(MODULE_NAME) *.S
install:
	adb push $(MODULE_NAME) $(PATH_ANDROID)
	adb shell chmod 755 $(PATH_ANDROID)$(MODULE_NAME)
	adb shell $(PATH_ANDROID)$(MODULE_NAME)

<2>.编写exp.c
#include 
int main(){
  int a;
  int b;
  int c;
  int d;
  int e;
  int f;
  int g;
  a = 123;
  b=a+1;
  c=b-2;
  d=c*2;
  e=d<<2;
  printf("e = %d\n",a+b+c+d+e);
}

<3>.push到android设备或者模拟器验证
# adb push exp /data/local

 

你可能感兴趣的:(ARM,NEON学习,Android逆向)