编译在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.下载 ...
随机推荐
- Hibernate3 第三天
Hibernate3 第三天 第一天:三个准备.七个步骤 第二天:一级缓存.快照.多对多和一对多的配置 学习内容: Hibernate的查询详解(各种检索(fetch)对象的方式) 1)条件查询分类( ...
- Struts2-3.struts.xml的action可以简写
如果只是跳转到某个页面的话,可以这样写 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE s ...
- iOS开发下架在AppStore中销售的app
1.登陆开发者账号 2.选择itunes connect 选择我的app 3.选择要下架的app 4.价格与销售范围 5.销售范围 6.点击存储 //如果想要重新在AppStore中进行销售只需要选择 ...
- POJ 2977 Box walking
题目链接:http://poj.org/problem?id=2977 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 222 ...
- hdu_5961_传递(bitset)
题目链接:hdu_5961_传递 题意: 中文,不解释 题解: 上bitset卡常,很优美的就过去了 #include<bits/stdc++.h> #define F(i,a,b) fo ...
- hdu_2825_Wireless Password(AC自动机+状压DP)
题目链接:hdu_2825_Wireless Password 题意: 给你m个串,问长度为n至少含k个串的字符串有多少个 题解: 设dp[i][j][k]表示考虑到长度为i,第j个自动机的节点,含有 ...
- Iphone CPU 架构类型
armv6设备:iPhone, iPhone2, iPhone 3G,第一代.第二代iPod Touch armv7设备:iPhone 3GS, iPhone 4, iPhone 4S iPad , ...
- Gentoo本地化设置--时区、时钟、字体、中文环境
时区 你需要选择时区让系统知道你的地理位置,以保持正确的时间.在/usr/share/zoneinfo中查找你的时区.然后在/etc/conf.d/clock中设置时区.请忽略/usr/share/z ...
- 使用某些Widows API时,明明包含了该头文件,却报错“error C2065: undeclared identifier”
在使用一些新版本的API,或者控件的新特性(比如新版的ComCtl32.dll)的时候,你可能会得到“error C2065: undeclared identifier.“这个错误.原因是这些功能是 ...
- jq 进度条插件
/***进度条*/var ProgressScrollBar = function (model) { this.defaults = { isCanMove: true,//是否启用拖动 conta ...