zoukankan      html  css  js  c++  java
  • Android下运行c程序

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

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

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

    下载完之后,bin目录下的arm-none-linux-gnueabi-gcc就是交叉编译器了

    #include <stdio.h>
    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

  • 相关阅读:
    准备改进回复功能
    今天的任务
    日历已加上
    web.config中globalization设置的问题
    Request获取url信息的各种方法比较
    增加了高级评论功能
    如何修改日历的CSS
    推荐有关MasterPages的三篇文章
    如何定制日历控件显示的星期文字
    FreeTextBox的问题终于解决了
  • 原文地址:https://www.cnblogs.com/mahang/p/2163355.html
Copyright © 2011-2022 走看看