본문 바로가기

프로그래밍/Android

안드로이드 플랫폼 포팅~holloworld 샘플 2

 

* 안드로이드 플랫폼 helloworld 예제 2 *

helloworld 예제 2는 c++ 클래스 사용방법을 보여주며, 예제 1과 마찬가지로

안드로이드 플랫폼 소스를 사용해 빌드한다.

 

> Helloworld.cpp

#include <stdlib.h>

#include <stdio.h>

#include "test.h"

 

int main(int argc, char** argv) {

CMyTest *temp=NULL;

temp = new CMyTest();

temp->testSample();

delete temp;

temp = NULL;

 

return 0;

}

 

> Test.h

#pragma once

 

class CMyTest {

public:

CMyTest();

~CMyTest();

void testSample();

};


> Test.cpp

#include <stdlib.h>

#include <stdio.h>

#include "test.h"


CMyTest::CMyTest()

{

}

CMyTest::~CMyTest()

{

}

void CMyTest::testSample() 

{

printf("Hello world!!");

}

 

> Makefile

PLATFORM := /home/bin/android-platform-donut

NDK := $(PLATFORM)/development/ndk

TOOL_CHAIN := $(PLATFORM)/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1

 

SRCS = helloworld.cpp \

test.cpp

 

OBJS = $(SRCS:.cpp=.o)

 

SRCS= $(OBJS:.o=.c)

TARGET=helloworld

 

INC :=  -I$(NDK)/build/platforms/android-4/arch-arm/usr/include \

-I$./

 

CC := $(TOOL_CHAIN)/bin/arm-eabi-gcc

CCPP := $(TOOL_CHAIN)/bin/arm-eabi-g++

AS := $(TOOL_CHAIN)/bin/arm-eabi-as

AR := $(TOOL_CHAIN)/bin/arm-eabi-ar

 

CPPFLAGS := $(INC) \

$(PV_INCLUDES) \

-D__ARM_ARCH_5__ \

-D__ARM_ARCH_5T__ \

-D__ARM_ARCH_5E__ \

-D__ARM_ARCH_5TE__ 

 

CFLAGS += -march=armv5te \

-mtune=xscale \

-msoft-float \

-fpic \

-mthumb-interwork \

-ffunction-sections \

-funwind-tables \

-fno-short-enums \

-funswitch-loops \

-fno-exceptions \

 

CXXFLAGS := -fno-exceptions -fno-rtti

 

LDFLAGS := -nostdlib \

-Bdynamic \

-Wl,-T,$(PLATFORM)/build/core/armelf.x \

-Wl,-dynamic-linker,/system/bin/linker \

-Wl,--gc-sections \

-Wl,-z,nocopyreloc \

 

LIBS := -Wl,-rpath-link=$(NDK)/build/platforms/android-4/arch-arm/usr/lib \

-L$(NDK)/build/platforms/android-4/arch-arm/usr/lib \

-lstdc++ \

-lc \

-lm 

 

 

PRELINK = $(NDK)/build/platforms/android-4/arch-arm/usr/lib/crtbegin_dynamic.o

POSTLINK = $(NDK)/build/platforms/android-4/arch-arm/usr/lib/crtend_android.o

 

 

 

%.o:%.cpp

@echo ----------------------------------------

@echo $@ : $<

@$(CC) $(CPPFLAGS)  $(CFLAGS) $(CXXFLAGS) -c $< -o $@

 

 

%.o:%.c

@echo ----------------------------------------

@echo $@ : $<

@$(CC) $(CFLAGS) -o $@ -c $<

 

$(TARGET): $(OBJS)

@echo ----------------------------------------

@echo $(TARGET) : $(OBJS)

@$(CC)  $(LDFLAGS) -o $@ $(PRELINK) $(OBJS) $(LIBS) $(POSTLINK)