android手机编译可运行的linux程序
2017-01-25 09:40
429 查看
测试平台:三星S4,内核3.4.5(华为p8上也测试通过,内核3.10.61)
Ubuntu版本:14.04
1. 搭建交叉编译环境
1.1 下载交叉编译工具:
arm-none-linux-gnueabi,下载地址:
http://www.codesourcery.com/sgpp/lite/arm/portal/package7851/public/arm-none-linux-gnueabi/arm-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
1.2 安装交叉编译工具:
将压缩包复制到/opt/toolchains/,运行解压命令tar -jxvf,解压得到arm-2010.09文件夹
1.3 配置环境变量
1) su nano ~/.bashrc
2) 在文件末尾添加如下的一行
export PATH=$PATH:/opt/toolchains/arm-2010.09-50/bin
3) 保存文件并退出
4) 运行命令 source ~/.bashrc
5) 当然可以用命令行验证一下是否成功 arm-none-linux-gnueabi-gcc -v。
注:配置好环境变量后,运行命令如果提示无法找到该文件,那么需要: apt-get install lib32z1,给系统装上32位软件的兼容库。
2. 编译C程序
新建hello.c
编译:arm-none-linux-gnueabi-gcc -static -o hello hello.c
注:必须加上-static,否则运行时会提示./hello: No such file or directory。也就是在编译时将函数都静态编译到程序中了,运行时不用再动态连接,如果不加此选项,在android平台上就不让运行。
3. 运行
adb连接手机
1) adb push hello /sdcard/
2) adb shell
3)./hello
Ubuntu版本:14.04
1. 搭建交叉编译环境
1.1 下载交叉编译工具:
arm-none-linux-gnueabi,下载地址:
http://www.codesourcery.com/sgpp/lite/arm/portal/package7851/public/arm-none-linux-gnueabi/arm-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
1.2 安装交叉编译工具:
将压缩包复制到/opt/toolchains/,运行解压命令tar -jxvf,解压得到arm-2010.09文件夹
1.3 配置环境变量
1) su nano ~/.bashrc
2) 在文件末尾添加如下的一行
export PATH=$PATH:/opt/toolchains/arm-2010.09-50/bin
3) 保存文件并退出
4) 运行命令 source ~/.bashrc
5) 当然可以用命令行验证一下是否成功 arm-none-linux-gnueabi-gcc -v。
注:配置好环境变量后,运行命令如果提示无法找到该文件,那么需要: apt-get install lib32z1,给系统装上32位软件的兼容库。
2. 编译C程序
新建hello.c
#include <stdio.h> int main() { printf("hello world android linux grograming\n"); return; }
编译:arm-none-linux-gnueabi-gcc -static -o hello hello.c
注:必须加上-static,否则运行时会提示./hello: No such file or directory。也就是在编译时将函数都静态编译到程序中了,运行时不用再动态连接,如果不加此选项,在android平台上就不让运行。
3. 运行
adb连接手机
1) adb push hello /sdcard/
2) adb shell
3)./hello
相关文章推荐
- ## WSQ Android手机用adb像Linux一样运行C程序
- Android 运行 C/C++程序 (使用 arm-linux-gcc 交叉编译环境)
- 安装交叉编译工具arm-none-linux-gnueabi-gcc——Linux上编译在android上运行的c程序
- Android 运行 C/C++程序 (使用 arm-linux-gcc 交叉编译环境)
- 在Android下运行Linux平台编译的程序
- Android 上,用普通的 am-linux-gcc 编译 C 程序。
- Eclipse开发Android程序如何在手机上运行
- Android ps 手机中正在运行的程序
- linux(ubuntu11.10)下手机真机调试eclipse上的android程序
- 在linux 上编译生成windows上运行的exe程序,交叉编译环境的配置( 平台:gentoo linux)
- 在linux中eclipse连接android手机开发程序
- 让Python在Android系统上飞一会儿:第三节 在电脑上编写程序在手机上运行
- Linux下编译运行C程序超高速教程
- 使用Python开发Android应用程序:第三节 在电脑上编写程序在手机上运行
- Eclipse开发Android程序如何在手机上运行
- 让C/C++程序一次编译,到处运行 (仅限Linux)
- 使用Python开发Android应用程序:第三节 在电脑上编写程序在手机上运行
- Eclipse开发Android程序如何在手机上运行
- 云平台编程与开发(三):创建基于X5Cloud云平台的Hello World程序(运行在Android的手机、平板上)
- 终于,我生命中第一次编译并运行了手机程序