We know that under Linux you can use GCC to compile a C code into an executable program on Linux, such as:
$ gcc-o main.out main.c
While the Android platform provides the NDK toolkit to cross-compile applications that can run on Android, it requires us to write android.mk to configure compilation options and compile targets, so can it be compiled directly from the command line like GCC?
The answer is yes, the NDK simply encapsulates and abstracts the process, and we can simply call the NDK-supplied compiler toolchain to compile our C code, as shown in the command line interface:
1. Define the relevant directory (please modify the relevant directory for yourself)
$ Export Ndkroot=/opt/android/android-ndk-r10
$ export sysroot= $NDKROOT/platforms/android-19/arch-arm
$ export gcc= $NDKROOT/TOOLCHAINS/ARM-LINUX-ANDROIDEABI-4.6/PREBUILT/LINUX-X86_64/BIN/ARM-LINUX-ANDROIDEABI-GCC
2. Compiling the Code
$ $GCC-o main.out main.c--sysroot= $SYSROOT
3. Execution Procedures
$ adb Push main.out/data/local/
$ adb shell
$/data/local/main.out
The core idea is actually very simple, is to use the NDK provided by the ARM-LINUX-ANDROIDEABI-GCC instead of the GCC tools under Linux, using the NDK provided by the C header file/library file directory instead of the default Linux directory, in fact, the use of GCC compiled by default Sysroot is set to the "/" Directory of this machine, equivalent to the following command:
$ gcc-o main.out main.c--sysroot=/
Friendly recommendation: Love encryption Android virus or will penetrate the Linux kernel drive layer http://www.ijiami.cn/newsInfo?id=207
Interpretation: Using the Android NDK cross-compilation tool in the case of commands