在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 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

./hello

更多相关文章

  1. 从CM刷机过程和原理分析Android系统结构
  2. 反编译并且修改Android(安卓)APK包
  3. Android实现pppoe拨号上网(二)具体步骤
  4. 在android下进行TDD开发
  5. 反编译并且修改Android(安卓)APK包
  6. findlibrary returned null产生的联想,Android(安卓)ndk开发打包
  7. android工程下运行main方法的配置方法
  8. Android工程的编译过程
  9. Android从启动到程序运行发生的事情

随机推荐

  1. 查看Android studio SHA1.无需输入命令
  2. Android显示调用App内部组件/第三方App内
  3. Android之网络请求7————OkHttp源码4:
  4. Android面试题总结(七)原理篇
  5. 在AndroidStudio中使用V8包中的RenderScr
  6. Android实现全屏的方法
  7. UI 开源代码 FileBrowserView
  8. android根据ListView内部Item最大长度来
  9. Android设定屏幕只竖屏或只横屏的两种方
  10. 如何关联androidSDK源代码