Ubuntu搭建嵌入式开发(交叉编译)环境
2012-10-23 11:31
381 查看
大家都比较熟悉gcc编译家族了,但是交叉编译到arm平台的代码是不直接使用gcc的,需要类似名字的一个程序。
1、首先写一个简单的c程序,helloArm.c, 如下:
2、查看gcc编译手册,进行初步编译尝试:
man gcc
主要的参数是 -march= ;尝试编译:
出现错误了。。。 gcc手册中不是有着个参数么?怎么无法使用? 然后网上搜索交叉编译的软件,结果发现需要一个专用的gcc, 名为gcc-arm-linux-gnueabi。
在ubuntu下安装非常方便,如下:
3、使用专用的gcc进行编译即可:
使用-S只生成汇编文件,可用于分析;得到默认编译后的helloArm.s版本:
看来默认是armv5t的平台,我买了一个开发板,是OK6410的,采用三星的S3C6410处理器,ARM1176JZF-S内核,主频533MHz/667MHz, 查看上一篇文章转载的各个arm体系对应的指令集,该处理器应该设置 -march=,编译如下:
结果:
到此,相应开发套件已经可用了,如果要生成对应二进制文件,跟使用常规的gcc一样,直接-o helloArm即可,如:
希望对大家有用;也欢迎大家多多指点和讨论;
1、首先写一个简单的c程序,helloArm.c, 如下:
/* * ===================================================================================== * * Filename: helloArm.c * * Description: * * Version: 1.0 * Created: 10/23/2012 10:36:00 AM * Revision: none * Compiler: gcc * * Author: QuNengrong (QNR), Quner8@gmail.com * Company: LordyWorkshop * * ===================================================================================== */ #include <stdio.h> int main(){ printf("hello, arm\n"); return 0; }
2、查看gcc编译手册,进行初步编译尝试:
man gcc
-mcpu=name This specifies the name of the target ARM processor. GCC uses this name to determine what kind of instructions it can emit when generating assembly code. Permissible names are: arm2, arm250, arm3, arm6, arm60, arm600, arm610, arm620, arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700, arm700i, arm710, arm710c, arm7100, arm720, arm7500, arm7500fe, arm7tdmi, arm7tdmi-s, arm710t, arm720t, arm740t, strongarm, strongarm110, strongarm1100, strongarm1110, arm8, arm810, arm9, arm9e, arm920, arm920t, arm922t, arm946e-s, arm966e-s, arm968e-s, arm926ej-s, arm940t, arm9tdmi, arm10tdmi, arm1020t, arm1026ej-s, arm10e, arm1020e, arm1022e, arm1136j-s, arm1136jf-s, mpcore, mpcorenovfp, arm1156t2-s, arm1156t2f-s, arm1176jz-s, arm1176jzf-s, cortex-a5, cortex-a7, cortex-a8, cortex-a9, cortex-a15, cortex-r4, cortex-r4f, cortex-r5, cortex-m4, cortex-m3, cortex-m1, cortex-m0, xscale, iwmmxt, iwmmxt2, ep9312, fa526, fa626, fa606te, fa626te, fmp626, fa726te. -mcpu=generic-arch is also permissible, and is equivalent to -march=arch -mtune=generic-arch. See -mtune for more information. -mcpu=native causes the compiler to auto-detect the CPU of the build computer. At present, this feature is only supported on Linux, and not all architectures are recognized. If the auto-detect is unsuccessful the option has no effect. -mtune=name This option is very similar to the -mcpu= option, except that instead of specifying the actual target processor type, and hence restricting which instructions can be used, it specifies that GCC should tune the performance of the code as if the target were of the type specified in this option, but still choosing the instructions that it will generate based on the CPU specified by a -mcpu= option. For some ARM implementations better performance can be obtained by using this option. -mtune=generic-arch specifies that GCC should tune the performance for a blend of processors within architecture arch. The aim is to generate code that run well on the current most popular processors, balancing between optimizations that benefit some CPUs in the range, and avoiding performance pitfalls of other CPUs. The effects of this option may change in future GCC versions as CPU models come and go. -mtune=native causes the compiler to auto-detect the CPU of the build computer. At present, this feature is only supported on Linux, and not all architectures are recognized. If the auto-detect is unsuccessful the option has no effect. -march=name This specifies the name of the target ARM architecture. GCC uses this name to determine what kind of instructions it can emit when generating assembly code. This option can be used in conjunction with or instead of the -mcpu= option. Permissible names are: armv2, armv2a, armv3, armv3m, armv4, armv4t, armv5, armv5t, armv5e, armv5te, armv6, armv6j, armv6t2, armv6z, armv6zk, armv6-m, armv7, armv7-a, armv7-r, armv7-m, iwmmxt, iwmmxt2, ep9312.
主要的参数是 -march= ;尝试编译:
$gcc -march=armv6zk -S helloArm.c helloArm.c:1:0: error: bad value (armv6zk) for -march= switch
出现错误了。。。 gcc手册中不是有着个参数么?怎么无法使用? 然后网上搜索交叉编译的软件,结果发现需要一个专用的gcc, 名为gcc-arm-linux-gnueabi。
在ubuntu下安装非常方便,如下:
$sudo apt-get install gcc-arm-linux-gnueabi
3、使用专用的gcc进行编译即可:
$arm-linux-gnueabi-gcc -S helloArm.c
使用-S只生成汇编文件,可用于分析;得到默认编译后的helloArm.s版本:
.arch armv5t .fpu softvfp .eabi_attribute 20, 1 .eabi_attribute 21, 1 .eabi_attribute 23, 3 .eabi_attribute 24, 1 .eabi_attribute 25, 1 .eabi_attribute 26, 2 .eabi_attribute 30, 6 .eabi_attribute 34, 0 .eabi_attribute 18, 4 .file "helloArm.c" .section .rodata .align 2 .LC0: .ascii "hello, arm\000" .text .align 2 .global main .type main, %function main: @ args = 0, pretend = 0, frame = 0 @ frame_needed = 1, uses_anonymous_args = 0 stmfd sp!, {fp, lr} add fp, sp, #4 ldr r0, .L3 bl puts mov r3, #0 mov r0, r3 ldmfd sp!, {fp, pc} .L4: .align 2 .L3: .word .LC0 .size main, .-main .ident "GCC: (Ubuntu/Linaro 4.7.2-1ubuntu1) 4.7.2" .section .note.GNU-stack,"",%progbits
看来默认是armv5t的平台,我买了一个开发板,是OK6410的,采用三星的S3C6410处理器,ARM1176JZF-S内核,主频533MHz/667MHz, 查看上一篇文章转载的各个arm体系对应的指令集,该处理器应该设置 -march=,编译如下:
$arm-linux-gnueabi-gcc -march=armv6zk -S helloArm.c
结果:
.arch armv6zk ;体系结构 .fpu softvfp .eabi_attribute 20, 1 .eabi_attribute 21, 1 .eabi_attribute 23, 3 .eabi_attribute 24, 1 .eabi_attribute 25, 1 .eabi_attribute 26, 2 .eabi_attribute 30, 6 .eabi_attribute 34, 1 .eabi_attribute 18, 4 .file "helloArm.c" .section .rodata .align 2 .LC0: .ascii "hello, arm\000" .text .align 2 .global main .type main, %function main: @ args = 0, pretend = 0, frame = 0 @ frame_needed = 1, uses_anonymous_args = 0 stmfd sp!, {fp, lr} add fp, sp, #4 ldr r0, .L3 bl puts mov r3, #0 mov r0, r3 ldmfd sp!, {fp, pc} .L4: .align 2 .L3: .word .LC0 .size main, .-main .ident "GCC: (Ubuntu/Linaro 4.7.2-1ubuntu1) 4.7.2" .section .note.GNU-stack,"",%progbits
到此,相应开发套件已经可用了,如果要生成对应二进制文件,跟使用常规的gcc一样,直接-o helloArm即可,如:
$arm-linux-gnueabi-gcc -o helloArm helloArm.c
希望对大家有用;也欢迎大家多多指点和讨论;
相关文章推荐
- Ubuntu 搭建开发环境(QT+交叉编译)【嵌入式环境】
- Ubuntu搭建嵌入式开发(交叉编译)环境-转
- ubuntu下嵌入式开发环境的搭建
- 在Ubuntu上搭建嵌入式Linux开发环境
- Ubuntu下 嵌入式Qt开发环境的搭建
- Ubuntu下 嵌入式Qt开发环境的搭建
- Ubuntu下 嵌入式开发环境的搭建:
- ubuntu 步步为营之嵌入式开发环境搭建(完整版)
- ubuntu下S5PV210开发板嵌入式开发环境搭建
- Ubuntu下 嵌入式Qt开发环境的搭建
- Ubuntu下嵌入式Linux开发环境搭建
- [3]_嵌入式开发环境搭建1_在ubuntu16.04.3 安装配置nfs 和 tftp服务器
- 嵌入式linux开发——开发环境搭建(NFS共享, 交叉编译)
- Ubuntu下 嵌入式Qt开发环境的搭建
- Ubuntu下 嵌入式Qt开发环境的搭建
- Ubuntu下 Tiny6410嵌入式Qt开发环境的搭建
- ubuntu下嵌入式开发环境的搭建
- 嵌入式开发环境搭建_ubuntu13.10
- Ubuntu下搭建Linux嵌入式开发环境
- QT:Ubuntu下 嵌入式Qt开发环境的搭建