|< << >> >|

Android Hello World (2012/08/02)

Here a quick documentation on how to build a C program using the Android NDK for Linux. The program can be run with the Android Terminal.

Here’s the Makefile.

NDK = $(HOME)/android-ndk-r8b
TOOLCHAIN = /tmp/ndk-hello
SYSROOT = $(TOOLCHAIN)/sysroot
GCC = $(TOOLCHAIN)/bin/arm-linux-androideabi-gcc
STRIP = $(TOOLCHAIN)/bin/arm-linux-androideabi-strip
CFLAGS = -march=armv7-a -mfloat-abi=softfp -I$(SYSROOT)/usr/include
LDFLAGS = -Wl,--fix-cortex-a8 -L$(SYSROOT)/usr/lib

all: $(TOOLCHAIN) hello

hello: hello.o
        $(GCC) $(LDFLAGS) -o $@ hello.o
        $(STRIP) -s $@

.c.o:
        $(GCC) $(CFLAGS) -o $@ -c $<

clean:
        rm -f hello *.o .*.un~

$(TOOLCHAIN):
        $(NDK)/build/tools/make-standalone-toolchain.sh --install-dir=$@

And here’s the C program hello.c.

#include <stdio.h>

int main(int argc, char** argv) {
   printf("Hello world!!!\n");
   return 0;
}

Running make should cross-compile the program.

blog comments powered by Disqus

Latest News

2014/03/02

Why I like Object Oriented Programming using GNU Guile and GOOPS
More...

2013/09/04

Creating a calculator with Bison, Flex, and Automake
More...

2012/11/07

The choice of programming language plays a fundamental role in the implementation of machine vision systems ...
More...

2012/08/02

Building a dynamically linked C program for Android
More...

2012/07/21

Running the Racket programming language on an Android phone
More...

2012/06/10

Comparison of the Clojure programming language with Scheme/LISP
More...

2011/10/20

Can we attract good and bad things with our mind?
More...

2011/09/25

Detecting the corners of a calibration grid
More...

...