Compiling C applications running on the Android platform

Source: Internet
Author: User

Android uses Bionic C instead of the usual glibc, so simply using the crossover toolchain does not compile a C + + program for running on Android devices.

The cross tool chain can be easily found in the Android source Prebuilts directory, but direct compilation will prompt you to find the header files for various standard libraries, and you need to specify the sysroot of the Bionic C library.

Android Toolchain, like the Tiny 6410 Development Board, can be used directly to compile C/D + + code because it integrates sysroot.

This article describes how to compile code (busybox) for any Android device (ARM v7a) using the NDK tools provided by Android.

1) Download Android NDK crossover tool chain and Sysroot

Http://developer.android.com/tools/sdk/ndk/index.html#Downloads

After decompression, the cross tool chain can be found in the following path

Android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin

arm-linux-androideabi-addr2line* arm-linux-androideabi-elfedit* arm-linux-androideabi-gcc-ranlib* arm-linux-androideabi-ld.gold* arm-linux-androideabi-readelf*
arm-linux-androideabi-ar* arm-linux-androideabi-g++* arm-linux-androideabi-gcov* Arm-linux-androideabi -ld.mcld* arm-linux-androideabi-run*
arm-linux-androideabi-as* arm-linux-androideabi-gcc* arm-linux-androideabi-gdb* Arm-linux-androideabi -nm* arm-linux-androideabi-size*
arm-linux-androideabi-c++* arm-linux-androideabi-gcc-4.8* arm-linux-androideabi-gprof* Arm-linux-androideabi -objcopy* arm-linux-androideabi-strings*
arm-linux-androideabi-c++filt* arm-linux-androideabi-gcc-ar* arm-linux-androideabi-ld* Arm-linux-androideabi -objdump* arm-linux-androideabi-strip*
arm-linux-androideabi-cpp* arm-linux-androideabi-gcc-nm* arm-linux-androideabi-ld.bfd* Arm-linux-androideabi -ranlib*

It is a good idea to add this path to the environment variable.


Android-ndk-r9/platforms/android-18/arch-arm the path below is the Android API18 Sysroot.

by http://source.android.com/source/build-numbers.html#platform-code-names-versions-api-levels-and-ndk-releases Gets the corresponding relationship between the API version and the Android release version.

2) Compiling a simple Hello World

$ cat HELLO.C
#include <stdio.h>
#include <stdlib.h>

int main (int argc, char* argv[])
{
printf ("Hello World! \ n ");
return 0;
}

$ arm-linux-androideabi-gcc-o Hello--sysroot=/home/xxx/android-ndk-r9/platforms/android-18/arch-arm/hello.c

3). Transplant BusyBox

$ git clone git://busybox.net/busybox.git

busybox$ cp configs/android_ndk_defconfig. config

$ make Menuconfig

Modify the Sysroot config to its own path.

$ make-j 8

$ make Install

Default installation to _install/under current path

$ adb Push _install/data/busybox/

Reference:

Https://github.com/tias/android-busybox-ndk

That ' s all! Enjoy your busybox on your own Android now!

Compiling C applications running on the Android platform

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.