android交叉编译c程序

本文详细介绍了如何使用arm-2012.03交叉编译工具进行嵌入式项目的编译流程,包括环境搭建、配置路径、编译测试代码等步骤,并解决了64位Ubuntu下使用32位编译器的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

在文件末尾添加

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

4.测试

arm-none-linux-gnueabi-gcc -v
 

5.编写helloworld.c

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


6.编译

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

7.查看

snail@ubuntu:~/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!
#

 

 

 

可能问题:

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

error: arm-none-linux-gnueabi-gcc: No such file or directory  

 

解决:

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值