Android native C Development: Environment Building

Source: Internet
Author: User

Original article: http://blog.sina.com.cn/s/blog_4a0a39c30100auh9.html

 

Android is a Linux-based operating system with an ARM processor. Therefore, you need a cross-compiler to compile Android programs on x86 systems such as Linux and Windows.

In Linux, You can compile a cross-compiling environment by yourself, but in Windows, it is complicated (or you can compile one in cygwin ), however, you can download a ready-made cross-compilation environment:

Http://www.codesourcery.com/gnu_toolchains/arm/download.html

Windows:

Http://www.codesourcery.com/gnu_toolchains/arm/portal/package3400/public/arm-none-linux-gnueabi/arm-2008q3-41-arm-none-linux-gnueabi.exe

Linux:

Http://www.codesourcery.com/gnu_toolchains/arm/portal/package3399/public/arm-none-linux-gnueabi/arm-2008q3-41-arm-none-linux-gnueabi.bin

 

After the installation, set the bin directory of the codesourcery Compiler (my directory is D:/Program
Files/codesourcery/sourcery g ++ lite/bin)
Join your path environment variable to start your android native C development journey. Write a simple C program:

# Include <stdlib. h>

Int main (INT argc, char ** argv ){
Printf ("Hello android! /Ni's M % s! /Ni like android
Very much !!! /N "," Martin foo ");
 
Return 0;
}

Save it as hello. C and enter the command line mode to ensure that the bin directory of the cross compiler and Android
The SDK tools directory is in the path of your system environment variable and compiled with the following command:

Arm-None-Linux-gnueabi-gcc-static hello. C-O hello

Note: you must add the static parameter. Otherwise, compiled files may not run on Android.

 

Start the android simulator and use the following command to push the file to the android simulator:

ADB shell mkdir/dev/sample
ADB push Hello/dev/sample/Hello

ADB shell chmod 777/dev/sample/Hello

 

Create the/dev/sample directory, upload the compiled hello, and change "hello" to executable.

Go to the command line mode and enter the android shell environment:

ADB Shell

# Cd/dev/sample

#./Hello

Enter the/dev/sample directory and execute "hello". The running result is as follows:

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.