在android 上面 运行纯C helloworld

由于要测系统的CPU属性,需要独立编译应用程序,便试了下编译纯C 程序,测试通过。

 

CC         := $(NDK_BASE)/toolchain/arm-eabi/bin/arm-eabi-gcc
AR         := $(NDK_BASE)/toolchain/arm-eabi/bin/arm-eabi-ar

INC        := -I$(NDK_BASE)/include/bionic/arch-arm/include /
 -I$(NDK_BASE)/include/bionic/include /
 -I$(NDK_BASE)/include/kernel/include /
 -I$(NDK_BASE)/include/libm/include /
 -I$(NDK_BASE)/include/libm/include/arm /
 -I$(NDK_BASE)/include/libstdc++/include

LINK       := -nostdlib -Bdynamic /
     -Wl,-T,$(NDK_BASE)/config/armelf.x /
     -Wl,-dynamic-linker,/system/bin/linker /
     -Wl,-z,nocopyreloc /
     -L$(NDK_BASE)/lib /
     -Wl,-rpath-link=$(NDK_BASE)/lib /
    $(NDK_BASE)/lib/crtbegin_dynamic.o

POSTLINK := $(NDK_BASE)/lib/crtend_android.o

%.o: %.cpp
 $(CC) $(CFLAGS) -fno-exceptions -fno-rtti $(INC) -o $@ -c $<
 
%.o: %.c
 $(CC) $(CFLAGS) $(INC) -o $@ -c $<

 

 include ./config.mk

EXECUTABLE := TEST
SOURCES    := main.c
OBJECTS    := $(SOURCES:.c=.o)
LIBS       := -lc -lm
all: $(EXECUTABLE)

# need $(LINK) before all objects and $(POSTLINK) after all objects for
# android runtime setup.

TEST: $(OBJECTS)
 $(CC) $(LINK) -o $@ $(OBJECTS) $(LIBS) $(POSTLINK)

clean:
 rm -rf *.o

 rm EXECUTABLE

 

测试程序 就是 printf("Hello world")

 

 

另外注意下,一般上传到手机data目录,并chmod下

 

 

你可能感兴趣的:(在android 上面 运行纯C helloworld)