Interpretation: Using the Android NDK cross-compilation tool in the case of commands

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.