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: