简体   繁体   English

编译ARM时GCC错误

[英]GCC Error while compiling for ARM

I am getting the following error while trying to compile some code for an ARM Cortex-M4 using 我尝试使用ARM Cortex-M4编译一些代码时收到以下错误

gcc -mcpu=cortex-m4 arm.c  

`-mcpu=' is deprecated. Use `-mtune=' or '-march=' instead.
arm.c:1: error: bad value (cortex-m4) for -mtune= switch

I was following GCC 4.7.1 ARM options . 我正在关注GCC 4.7.1 ARM选项 Not sure whether I am missing some critical option. 不确定我是否缺少一些关键选项。 Any kickstart for using GCC for ARM will also be really helpful. 任何使用GCC for ARM的kickstart也会非常有用。

As starblue implied in a comment, that error is because you're using a native compiler built for compiling for x86 CPUs, rather than a cross-compiler for compiling to ARM. 正如starblue在评论中暗示的那样,该错误是因为您使用的是为x86 CPU编译而构建的本机编译器,而不是用于编译ARM的交叉编译器。

GCC only supports a single general architecture type in any given compiler binary -- so, although the same copy of GCC can compile for both 32-bit and 64-bit x86 machines, you can't compile to both x86 and ARM with the same copy of GCC -- you need an ARM-specific GCC. GCC在任何给定的编译器二进制文件中仅支持单一的通用体系结构类型 - 因此,尽管GCC的相同副本可以为32位和64位x86机器编译,但您无法使用相同的方式编译到x86和ARM GCC的副本 - 您需要一个特定于ARM的GCC。

(As auselen suggests, getting a pre-built one will save you quite a lot of work, even if you're only using it as a starting point to get things set up. You need to have GCC, binutils, and a C library as a minimum, and those are all separate open-source projects that the pre-built versions have already done the work of combining. I'll recommend Sourcery CodeBench Lite since that's the one my company makes and I do think it's a fairly good one.) (正如auselen建议的那样,获得一个预先构建的工作将为你节省大量的工作,即使你只是用它作为设置的东西的起点。你需要有GCC,binutils和C库至少,这些都是独立的开源项目,预先构建的版本已经完成了组合工作。我会推荐Sourcery CodeBench Lite,因为那是我公司制作的,我觉得它是一个相当不错的。)

As the error message says -mcpu is deprecated, and you should use the other options stated. 正如错误消息所示-mcpu已弃用,您应该使用其他选项。 However " deprectated " simply means that its use may not continue to be supported; 然而,“ 已经删除 ”只是意味着它的使用可能不会继续得到支持; it will still work. 它仍然有效。

ARM Cortex-M4 is ARM Architecture V7E-M, so you should use -march=armv7-m (the documentation does not specifically list armv7e-m , but that may have been added since the documentation was last updated. The E is essentially the difference between M3 and M4 - the DSP instructions, so the compiler will not generate code that takes advantage of these instructions. Using ARM's Cortex-M DSP library is probably the best way to use these instructions to benefit your application. If your part has an FPU, then other options will be needed enable code generation for that. ARM Cortex-M4是ARM体系结构V7E-M,所以你应该使用-march=armv7-m (文档没有特别列出armv7e-m ,但是自上次更新文档以来可能已经添加了E本质上是M3和M4之间的区别 - DSP指令,因此编译器不会生成利用这些指令的代码。使用ARM的Cortex-M DSP库可能是使用这些指令使您的应用受益的最佳方式。如果您的部件有一个FPU,然后需要其他选项来启用代码生成。

Like others already pointed out, you are using a compiler for your host machine, and you need a compiler for generating code for your target processor instead (a cross compiler). 像其他人已经指出的那样,您正在为主机使用编译器,而您需要一个编译器来为目标处理器生成代码(交叉编译器)。 Like @Brooks suggested, you can use a pre-built toolchain, but if you want to roll out your own cross-compiler, libc and binutils, there is a nice tool called Crosstool-NG . 就像@Brooks建议的那样,你可以使用预先构建的工具链,但是如果你想推出自己的交叉编译器libc和binutils,那么有一个很好的工具叫做Crosstool-NG It greatly simplifies the process of building a cross-compiler optimized to generate code for a specific processor, so you're not stuck with a generic prebuilt toolchain, which usually builds code for a family of compatible processors (eg you could tune the toolchain for generating ASM for your specific target, or floating point code for a hardware FPU which is specific to your processor, instead of using only software floating point routines, which are default to most pre-built toolchains). 它极大地简化了构建为特定处理器生成代码而优化的交叉编译器的过程,因此您不会遇到通用的预构建工具链,它通常为一系列兼容处理器构建代码(例如,您可以调整工具链为特定目标生成ASM,或者为处理器特定的硬件FPU生成浮点代码,而不是仅使用软件浮点例程,这些程序默认为大多数预先构建的工具链。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM