It is important for the build what the Embedded device code that the cross compilation tools.For the android devices, we are interested in the device’s cross-compilation tool.
In the $(project)/kernel-3.18/Android.mk file, the information about the build command as follow:
KERNEL_MAKE_OPTION := O=$(KERNEL_OUT) ARCH=$(TARGET_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) ROOTDIR=$(KERNEL_ROOT_DIR) $(if $(strip $(SHOW_COMMANDS)),V=1)
…
$(MAKE) -C $(KERNEL_DIR) $(KERNEL_MAKE_OPTION) $(KERNEL_DEFCONFIG)
Due to the makefile can print the command that perform compilation, we can find the information for the build log. In the log, there is information about the cross compilation tools:
make -C kernel-3.18 O=/work/dongyong/MT6797_Android_Marshmallow_6.0/out/target/product/amt6797_evb_m/obj/KERNEL_OBJ ARCH=arm64 CROSS_COMPILE=/work/dongyong/MT6797_Android_Marshmallow_6.0/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android- ROOTDIR=/work/dongyong/MT6797_Android_Marshmallow_6.0 amt6797_evb_m_debug_defconfig
There is the gcc tool what is name to aarch64-linux-android-gcc-4.9 in the $(project)/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin directory’s information :
So the cross-compilation tool is $(project)/prebuilts/gcc/linux-x86/aarch64/-
-aarch64-linux-android-4.9/bin/aarch64-linux-android-gcc
2.For example we can build a executable file by using the tool.
The Sample code as follow:
#include <stdio.h>
struct a{
int i;
};
int main()
{
struct a aa;
aa.i = 10;
printf("====dyong====aa.i=%d\n",aa.i);
return 0;
}
The makefile:
MY_OUT=/work/dongyong/MT6797_Android_Marshmallow_6.0/out/target/product/a mt6797_evb_m
MY_ANDROID_TOOLCHAIN=/work/dongyong/MT6797_Android_Marshmallow_6.0/pre builts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin
MY_ANDROID_BUILD_TOP=/work/dongyong/MT6797_Android_Marshmallow_6.0
CC=$(MY_ANDROID_TOOLCHAIN)/aarch64-linux-android-gcc
INCLUDE= -I$(MY_ANDROID_BUILD_TOP)/bionic/libc/arch-arm64/include -I$(MY_ANDROID_BUILD_TOP)/bionic/libc/kernel/uapi/asm-arm64 -I$(MY_ANDROID_BUILD_TOP)/bionic/libm/include -I$(MY_ANDROID_BUILD_TOP)/bionic/libm/include/arm64
LDFLAGS= -nostdlib -Bdynamic -fPIE -pie -Wl,-dynamic-linker,/system/bin/linker64 -Wl,–gc-sections -Wl,-z,nocopyreloc -L$(MY_OUT)/obj/lib -Wl,-rpath-link=$(MY_OUT)/obj/lib $(MY_OUT)/obj/lib/crtbegin_dynamic.o -Wl,–whole-archive -Wl,–no-whole-archive -lc -lstdc++ -lgcc -lm -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,–warn-shared-textrel -Wl,–fatal-warnings -Wl,–no-undefined -ldl
main:
$(CC) $(INCLUDE) $(LDFLAGS) amt_example.c -o amt_example
Running the follow command to generate executable files amt_example.
$make
Pushing the executable file to android devices by the adb tool.
Using the adb tool connect the android devices, execute the amt_example and get the results as follow: