在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下

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章