编译在android 平台上跑的C应用程序
Android 用的是 Bionic C, 而不是通常的glibc,因此简单使用交叉工具链并不能够编译出适合运行在android 设备上的 C/C++ 程序。
交叉工具链可以很轻松在 Android 源码 prebuilts 目录下找到,但是直接编译会提示找不到各种标准库的头文件,需要指定 Bionic C库 的 sysroot.
像 Tiny 6410 开发板带的Android toolchain 因为集成了sysroot,因此可以直接用于编译C/C++ 代码。
本文讲述如何为任何一个Android 设备(ARM v7a )使用 android 提供的NDK 工具编译代码(busybox)。
1) 下载 Android NDK 交叉工具链及 sysroot
http://developer.android.com/tools/sdk/ndk/index.html#Downloads
解压之后,在下面的路径中可以找到交叉工具链
android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin
arm-linux-androideabi-addr2line* arm-linux-androideabi-elfedit* arm-linux-androideabi-gcc-ranlib* arm-linux-androideabi-ld.gold* arm-linux-androideabi-readelf*
arm-linux-androideabi-ar* arm-linux-androideabi-g++* arm-linux-androideabi-gcov* arm-linux-androideabi-ld.mcld* arm-linux-androideabi-run*
arm-linux-androideabi-as* arm-linux-androideabi-gcc* arm-linux-androideabi-gdb* arm-linux-androideabi-nm* arm-linux-androideabi-size*
arm-linux-androideabi-c++* arm-linux-androideabi-gcc-4.8* arm-linux-androideabi-gprof* arm-linux-androideabi-objcopy* arm-linux-androideabi-strings*
arm-linux-androideabi-c++filt* arm-linux-androideabi-gcc-ar* arm-linux-androideabi-ld* arm-linux-androideabi-objdump* arm-linux-androideabi-strip*
arm-linux-androideabi-cpp* arm-linux-androideabi-gcc-nm* arm-linux-androideabi-ld.bfd* arm-linux-androideabi-ranlib*
最好将这个路径加入到环境变量。
android-ndk-r9/platforms/android-18/arch-arm 这个路径下面放的是 Android API18 的sysroot.
通过http://source.android.com/source/build-numbers.html#platform-code-names-versions-api-levels-and-ndk-releases 获取API 版本和android 发行版本的对应关系。
2) 编译简单的 hello world
$ cat hello.c
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
printf("Hello world ! \n");
return 0;
}
$ arm-linux-androideabi-gcc -o hello --sysroot=/home/xxx/android-ndk-r9/platforms/android-18/arch-arm/ hello.c
3). 移植 busybox
$ git clone git://busybox.net/busybox.git
busybox$ cp configs/android_ndk_defconfig .config
$ make menuconfig
修改 sysroot config 到自己的路径。
$ make -j 8
$ make install
默认安装到 当前路径下的 _install/
$ adb push _install /data/busybox/
参考:
https://github.com/tias/android-busybox-ndk
That's all ! Enjoy your busybox on your own Android Now !
编译在android 平台上跑的C应用程序的更多相关文章
- [原]详解如何将cocos2dx项目编译到Android平台上的(方式一:Cywin+NDK)
链接地址:http://m.blog.csdn.net/blog/yhc13429826359/29357815 2014-6-8阅读578 评论0 前言:cocos2dx作为一个开源的移动2D游戏框 ...
- 让“是男人就下到100层”在Android平台上跑起来
原工程:https://github.com/jeekun/DownFloors 移植后的代码:HelloCpp.zip 移植后的APK:HelloCpp.apk 说明:(cocos2d-x版本是“ ...
- Android平台上最好的几款免费的代码编辑器
使用正确的开发工具能够快速有效地完成源代码的编写和测试,使编程事半功倍.在网络信息高速发展的今天,移动设备的方便快捷已经深入人心,越来越多的程序员会选择在任何感觉舒适的地方使用移动设备查看或者编辑源代 ...
- Mac系统下编译支持Android平台的最新X264编码器
Mac系统下编译支持Android平台的最新X264编码器 原文来自 http://www.mingjianhua.com,转载请注明出处 1.首先去官网下载最新的x264源代码,解压到任意目录 ht ...
- Qt在Android平台上实现html转PDF的功能
Qt for Android Qt for Android enables you to run Qt 5 applications Android devices. All Qt modules ( ...
- 随笔之Android平台上的进程调度探讨
http://blog.csdn.net/innost/article/details/6940136 随笔之Android平台上的进程调度探讨 一由来 最近在翻阅MediaProvider的时候,突 ...
- (转) Android平台上关于IM的实践总结
前言 IM通信在互联网发展到现在已经是码农的世界里人尽皆知的技术,特别在当下移动互联网迅猛发展的时代这种技术的开发也更加火热,其中老牌的代表作就有QQ和MSN,和最近新崛起的微信,默默,易信,来往等眼 ...
- OpenCV在Android平台上的应用
今年8月份, OpenCV 2.3.1发布了. 虽然从2.2开始, OpenCV就号称支持Android平台, 但真正能让OpenCV在Android上运行起来还是在2.3.1版本上. 在这个版本上, ...
- unity3D开发的程序发布到Android平台上进行运行测试的详细步骤
第一步 下载安装JDK 和SDK 1.需要配置java环境.点击链接进入ava的配置的方法:http://www.cnblogs.com/Study088/p/7496158.html 2.下载 ...
随机推荐
- Java线程的几种状态
一. 线程状态类型1. 新建状态(New):新创建了一个线程对象.2. 就绪状态(Runnable):线程对象创建后,其他线程调用了该对象的start()方法.该状态的线程位于可运行线程池中,变得可运 ...
- Monkey总结
Monkey是一个快速检查内存泄露的好工具,可以初步发现较明显的内存泄露问题. 什么是内存泄露?是指不在使用的对象持续占有内存,造成内存空间的浪费. 检查内存泄露的基本操作步骤: 1.运行Monkey ...
- String类之indexOf--->查找某字对应的位置
以下方法都是java内置类String类的内置方法(不是构造方法哦,就是普通的方法),不需要我们写,直接拿过来用即可. indexOf方法对应Api介绍 lastIndexOf方法对应Api介绍 -- ...
- 获取radio的值
随着Jquery的作用越来越大,使用的朋友也越来越多.在Web中,由于CheckBox.Radiobutton .DropDownList等控件使用的频率比较高,就关系到这些控件在Jquery中的操作 ...
- C#字符串转INT
Convent.ToInt32(string ) 可以转化字符串 其他 * .tostring(); (int ) char //强制类型转换 不能转化字符串
- php 导出 Excel 报错 exception 'PHPExcel_Calculation_Exception' with message
exception 'PHPExcel_Calculation_Exception' with message '粉丝数据!C2679 -> Formula Error: Operator '= ...
- Linux压缩与解压缩
.tar.gz 和 .tgz解压:tar zxvf FileName.tar.gz [-C Dir] 中括号中的内容可以省略.压缩:tar zcvf FileName.tar.gz DirName . ...
- OpenLayer
<html> <head> <meta charset="utf-8"> <title>GIS开发样例-V1.0</title ...
- IO.Path路径
string filePath =@"E:/Randy0528/中文目录/JustTest.rar"; 更改路径字符串的扩展名.System.IO.Path.ChangeExten ...
- crontab定时任务
使用cron服务,用 service crond status 查看 cron服务状态,如果没有启动则 service crond start启动它, cron服务是一个定时执行的服务,可以通过cro ...