Chinaunix首页 | 论坛 | 博客
  • 博客访问: 335378
  • 博文数量: 96
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 152
  • 用 户 组: 普通用户
  • 注册时间: 2013-09-02 09:27
文章分类

全部博文(96)

文章存档

2017年(2)

2016年(30)

2015年(38)

2014年(25)

2013年(1)

我的朋友

分类: LINUX

2015-09-02 14:16:35

在android的设计中,谷歌设计了一套专门为嵌入式设备使用的bionic C库,以替换原有的GUN Libc,这个精简的bionic库据说只有200多K,所以如果只想使用这个精简的C库像在linux下一样 开发C程序,基本是不可能的。当然如果只想让其在shell中运行还是可以做到的。

因为编译完的目标程序是在android下运行,就要使用交叉编译的工具,在下面地址下载:

下载完之后,bin目录下的arm-none-linux-gnueabi-gcc就是交叉编译器了
或者在linux服务器上路径下查找:
/opt/toolchains/arm-2008q3/bin/arm-none-linux-gnueabi-gcc 

#include
int main() {
    printf("nihao a\n");
    printf("你好 啊\n");
    return 1;
}

输入一下命令:

./arm-none-linux-gnueabi-gcc hello.c -o hello -static

-static选项在这里是必须的,否则会出现”not found”的错误。

然后就可以把编译好的hello传到手机上运行了。不过这里有个前提条件,要求android机器必须是root过的,好像简单的z4root还不行,必须使用更彻底的root方法,关于如何root,这里就不再赘述了,可以参考相关root的帖子。

adb push hello /dev/sample/

这里要上传的目录必须是root用户所有的。

然后就是运行程序,可以在adb shell里测试

adb shell

cd /dev/sample/

chmod 777 hello

./hello

或者在手机上安装超级终端,在终端里运行

./hello

阅读(1129) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~