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=/
about how to use the Android NDK cross-compiler tool on the command line is introduced here, I hope to help you, have any questions or suggestions welcome message or letter [email protected] exchange, or follow my Sina Weibo @ Lu _ June get the latest articles and information.
This article is from the "Shadow Three People" blog, please be sure to keep this source http://ticktick.blog.51cto.com/823160/1692489
How to use the Android NDK cross-compilation tool at the command line