Using cross compiler


#1

After download the android source tree and following the instruction, I am able to compile the kernel and android etc.

But if I want to compile a hello world and run it on 410C, how do I use the cross compiler? I tried aarch64-linux-android-gcc but get an error of missing header file something. I guess the sysroot is not set right. What do I set the sysroot in the source tree?

Thanks,
G.


#2

First you need to download the ndk.
After that, I usually do something like below in a makefile:

NDK=/path/to/ndk, e.g. /home/android/android-ndk-r10e
SYSROOT=/path/to/sysroot, e.g. $(NDK)/platforms/android-21/arch-arm #make sure to select the version you need
TOOLCHAIN=/path/to/cross_compiler, e.g. $(NDK)/toolchains/android-toolchain-eabi-4.8-2014.04-x86

CC=$(TOOLCHAIN)/bin/arm-linux-androideabi-gcc-4.9
FLAGS=-sysroot=$(SYSROOT) -I$(SYSROOT_LINUX)/usr/include -fPIE -pie

all: hello

hello:
$(CC) $(FLAGS) -o $@

This is for arm so you might have to do some slight adjustments for aarch64.