They are more familiar with the gcc compiler family, but cross-compiling the code to arm platform is not directly using gcc, you need a program similar names.
1, first wrote a simple c program, helloArm.c, as follows:
1 /* 2 * ===================================================================================== 3 * 4 * Filename: helloArm.c 5 * 6 * Description: 7 * 8 * Version: 1.0 9 * Created: 10/23/2012 10:36:00 AM 10 * Revision: none 11 * Compiler: gcc 12 * 13 * Author: QuNengrong (QNR), [email protected] 14 * Company: LordyWorkshop 15 * 16 * ===================================================================================== 17 */ 18 #include <stdio.h> 19 int main(){ 20 printf("hello, arm\n"); 21 return 0; 22 }
2, see the gcc compiler manual, a preliminary attempt to compile:
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.
The main argument is the -march =; try to compile:
$gcc -march=armv6zk -S helloArm.c helloArm.c:1:0: error: bad value (armv6zk) for -march= switch
The error. . . gcc manual parameter has not it? How you can not be used? Then cross-compiled software online search and found the need for a dedicated gcc, named gcc-arm-linux-gnueabi.
In ubuntu installation is easy, as follows:
$sudo apt-get install gcc-arm-linux-gnueabi
3, using a dedicated gcc to compile:
$arm-linux-gnueabi-gcc -S helloArm.c
-S use only generate an assembly file, it can be used for analysis; get helloArm.s version of the default compiler:
1 .arch armv5t 2 .fpu softvfp 3 .eabi_attribute 20, 1 4 .eabi_attribute 21, 1 5 .eabi_attribute 23, 3 6 .eabi_attribute 24, 1 7 .eabi_attribute 25, 1 8 .eabi_attribute 26, 2 9 .eabi_attribute 30, 6 10 .eabi_attribute 34, 0 11 .eabi_attribute 18, 4 12 .file "helloArm.c" 13 .section .rodata 14 .align 2 15 .LC0: 16 .ascii "hello, arm\000" 17 .text 18 .align 2 19 .global main 20 .type main, %function 21 main: 22 @ args = 0, pretend = 0, frame = 0 23 @ frame_needed = 1, uses_anonymous_args = 0 24 stmfd sp!, {fp, lr} 25 add fp, sp, #4 26 ldr r0, .L3 27 bl puts 28 mov r3, #0 29 mov r0, r3 30 ldmfd sp!, {fp, pc} 31 .L4: 32 .align 2 33 .L3: 34 .word .LC0 35 .size main, .-main 36 .ident "GCC: (Ubuntu/Linaro 4.7.2-1ubuntu1) 4.7.2" 37 .section .note.GNU-stack,"",%progbits
The default view is armv5t platform, I bought a development board, it is OK6410, using Samsung's S3C6410 processor, ARM1176JZF-S core clocked at 533MHz / 667MHz, instructions to view the article reprinted each corresponding arm system set, the processor should be set -march =, compiled as follows:
$arm-linux-gnueabi-gcc -march=armv6zk -S helloArm.c
result:
1 .arch armv6zk ;体系结构 2 .fpu softvfp 3 .eabi_attribute 20, 1 4 .eabi_attribute 21, 1 5 .eabi_attribute 23, 3 6 .eabi_attribute 24, 1 7 .eabi_attribute 25, 1 8 .eabi_attribute 26, 2 9 .eabi_attribute 30, 6 10 .eabi_attribute 34, 1 11 .eabi_attribute 18, 4 12 .file "helloArm.c" 13 .section .rodata 14 .align 2 15 .LC0: 16 .ascii "hello, arm\000" 17 .text 18 .align 2 19 .global main 20 .type main, %function 21 main: 22 @ args = 0, pretend = 0, frame = 0 23 @ frame_needed = 1, uses_anonymous_args = 0 24 stmfd sp!, {fp, lr} 25 add fp, sp, #4 26 ldr r0, .L3 27 bl puts 28 mov r3, #0 29 mov r0, r3 30 ldmfd sp!, {fp, pc} 31 .L4: 32 .align 2 33 .L3: 34 .word .LC0 35 .size main, .-main 36 .ident "GCC: (Ubuntu/Linaro 4.7.2-1ubuntu1) 4.7.2" 37 .section .note.GNU-stack,"",%progbits
This, the corresponding development kits already available, if you want to generate the corresponding binary file, with the use of conventional gcc as direct -o helloArm, like this:
$arm-linux-gnueabi-gcc -o helloArm helloArm.c
I hope to be useful; we also welcome a lot of guidance and discussion;
Reproduced in: https: //www.cnblogs.com/QuLory/archive/2012/10/23/2735204.html