1. 建立交叉编译环境
首先下载并
安装交叉编译工具GNU/ARM
Linux gcc:
http://www.codesourcery.com/gnu_toolchains/arm/download.html
安装时 直接解压就行了,要设置好PATH环境变量。
2.编辑代码
简单的C代码:test.c
#include <stdio.h>
int main()
{
int i,j;
for(i=0;i<=10;i++)
{
for(j=0;j<=i;j++)
printf(”*”);
printf(”\n”);
}
return 0;
}
3.编译
# arm-none-linux-gnueabi-gcc test.c -o test -static
-static选项在这里是必须的,不然android平台就不运行此程序。
这也说明了此平台上的C/C++库是不能被C/C++程序动态连接的 。
4.上传(此前先启动android emulator)
$adb push test /data/data
5.执行
进入/data/data目录运行程序。
# cd /data/data
# ./test
补充:
a. C++程序一样的方法,只不过编译器换成:arm-none-linux-gnueabi-g++
b. 执行之前,需要chmod 777 test之
原文链接:
http://xiongcb.mentor100.com/200 ... %e7%a8%8b%e5%ba%8f/