Android native C Development (Backup test code compilation command)

Source: Internet
Author: User

Android is a Linux-based operating system with an ARM processor. Therefore, it is necessary to compile and run Android on x86 systems such as Linux or windows.Program, You need a cross compiler.

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

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

 

After the installation, add the bin directory of the codesourcery Compiler (my directory is D:/program files/codesourcery/sourcery g ++ lite/bin) to your path environment variable, you can start your android native C development journey and 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. Make sure that the bin directory of the cross compiler and the tools directory of the android SDK are in the path of your system environment variable. compile it 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.