Android下使用C语言的四种编译方式

24 篇文章 4 订阅
15 篇文章 0 订阅

http://blog.csdn.net/cl11010/article/details/8459981

一、编写helloworld.c Android.mk

[cpp]  view plain copy
  1. #include <stdio.h>    
  2. int main()    
  3. {    
  4.      printf("Hello World!\n");    
  5.      return 0;   
  6. }    
  7.   
  8. LOCAL_PATH:= $(call my-dir)    
  9. include $(CLEAR_VARS)    
  10. LOCAL_SRC_FILES:=hello.c    
  11. LOCAL_MODULE := helloworld    
  12. LOCAL_MODULE_TAGS := optional    
  13. include $(BUILD_EXECUTABLE)   

二.编译


1、使用NDK r5


ndk-build 命令的使用。
2、使用通用toolchain

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

adb push helloworld  /data
3、在源码环境中编译

在源码development 目录下创建hello目录,将helloworld.c Android.mk拷贝至hello目录下,然后mm即可。

4、使用源码自带Toolchain
在这之前要把上一步中的helloworld模块clean:

make clean-helloworld

使用showcommands选项重新编译helloworld,查看具体命令,从输出命令行可以看到,Android编译环境所用的交叉编译工具链是prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-gcc:

make  helloworld  showcommands 

(target Strip的作用是什么?)
        Android并没有采用glibc作为C库,而是采用了Google自己开发的Bionic Libc,通用的Toolchain用来编译和移植Android 的Linux内核是可行的,因为内核并不需要C库,但是开发Android的应用程序时,其他Toolchain编译的应用程序只能采用静态编译的方式才能运行,使用静态方式编译出来的执行文件都比较大。
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值