1.交叉编译工具


arm-2012.03-57-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2


2.解压


tar -xavf arm-2012.03-57-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2 -C /home/snail/bin


3.配置


gedit ~/.bashrc


在文件末尾添加(最开始心里没谱,所以跳过了这一步,我直接在arm-2010.09/bin文件夹下测试)


export PATH=~/bin/arm-2012.03/bin/:$PATH


4.测试


arm-none-linux-gnueabi-gcc -v

android交叉编译c程序_第1张图片

5.编写helloworld.c


#include <stdio.h>
int main()
{
printf("helloworld!\n");
return 0;
}


6.编译


arm-none-linux-gnueabi-gcc -o hello helloworld.c - static (在这我说下,我的环境是Ubuntu10.04 64位,后面的-static这个参数非常的重要)


7.查看


[email protected] :~/work/android/cross-c/1.helloworld$ file helloworld
helloworld: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, not stripped


8.执行


adb push 1.txt sdc


ard/


D:\adb\adb>adb push C:\Users\Administrator\Desktop\helloworld bin


adb shell





# chmod 777 hello
chmod 777 hello
# ./hello
./hello
helloworld!
#


android交叉编译c程序_第2张图片








可能问题:


64位ubuntu无法使用32位编译器。出现:


error: arm-none-linux-gnueabi-gcc: No such file or directory 很多人出现该为题,我是添加-static参数解决了,如果你添加参数没有解决,那么试下下面的


解决:


sudo apt-get install libc6:i386 libgcc1:i386 gcc-4.6-base:i386 libstdc++5:i386 libstdc++6:i386

更多相关文章

  1. Android camera预览参数以及实际图像大小设置
  2. Android自动测试代码
  3. Android junit实现多个Activity跳转测试
  4. Android Testing(1) 浅尝Android测试的奥秘
  5. (4.5.4)Android测试TestCase单元(Unit test)测试和instrumentation
  6. Android自动化测试框架—Robotium 4.3介绍
  7. Android实现EditText控件禁止输入内容的方法(附测试demo)
  8. Android入门:单元测试
  9. 使用android模拟事件,python完成自动化测试

随机推荐

  1. Android与服务器端数据交互(1)
  2. Android面试系列文章2018之Android部分之
  3. Android(安卓)Sensor传感器系统架构初探
  4. 为什么iOS比Android更吸引开发者
  5. 创建你的第一个Android(安卓)PHP应用
  6. Android(安卓)的 selector--背景选择器
  7. 穿越之旅之--android中如何执行java命令
  8. Android之进程与线程
  9. Android(安卓)NDK环境搭建
  10. android静默安装的实现(一)