如何使用单个 GCC(交叉)编译器(交叉)编译为 ARM 硬浮点和软浮点(softfp)? [英] How to (cross-)compile to both ARM hard- and soft-float (softfp) with a single GCC (cross-)compiler?

查看:56
本文介绍了如何使用单个 GCC(交叉)编译器(交叉)编译为 ARM 硬浮点和软浮点(softfp)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用单个(交叉)编译器来为不同的 ARM 调用约定编译代码:因为我总是想使用浮点和 NEON 指令,所以我只想选择硬浮点调用约定或软浮点 (softfp) 调用约定.

I'd like to use a single (cross-)compiler to compile code for different ARM calling conventions: since I always want to use floating point and NEON instructions, I just want to select the hard-float calling convention or the soft-float (softfp) calling convention.

我的编译器默认为硬浮点,但它支持我需要的两种架构:

My compiler defaults to hard-float, but it supports both architectures that I need:

$ arm-linux-gnueabihf-gcc -print-multi-lib
.;
arm-linux-gnueabi;@marm@march=armv4t@mfloat-abi=soft
$

当我使用默认参数编译时:

When I compile with the default parameters:

$ arm-linux-gnueabihf-g++ -Wall -o hello_world_armhf hello_world.cpp

它成功了,没有任何错误.

It succeeds without any errors.

如果我用 -print-multi-lib 返回的参数编译:

If I compile with the parameters returned by -print-multi-lib:

$ arm-linux-gnueabihf-g++ -marm -march=armv4t -mfloat-abi=soft -Wall -o hello_world hello_world.cpp

它再次编译没有错误(顺便说一下,我如何测试结果代码是硬浮点还是软浮点?)

It again compiles without error (By the way, how can I test that the resultant code is hard- or soft-float?)

不幸的是,如果我尝试这样做:

Unfortunately, if I try this:

$ arm-linux-gnueabihf-g++ -march=armv7-a -mthumb-interwork -mfloat-abi=softfp -mfpu=neon -Wall -o hello_world hello_world.cpp
[...]/gcc/bin/../lib/gcc/arm-linux-gnueabihf/4.7.3/../../../../arm-linux-gnueabihf/bin/ld: error: hello_world uses VFP register arguments, /tmp/ccwvfDJo.o does not
[...]/gcc/bin/../lib/gcc/arm-linux-gnueabihf/4.7.3/../../../../arm-linux-gnueabihf/bin/ld: failed to merge target specific data of file /tmp/ccwvfDJo.o
collect2: error: ld returned 1 exit status
$

我已经测试了参数的一些其他排列,但似乎除了 -print-multi-lib 显示的组合之外的任何东西都会导致错误.

I've tested some other permutations of the parameters, but it seems that anything other than the combination shown by -print-multi-lib results in an error.

我读过 ARM 编译错误, VFP 注册由可执行文件使用,而不是目标文件,但问题是二进制文件的某些部分是软浮动的,而某些是硬浮动的.我有一个 C++ 文件要编译...

I've read ARM compilation error, VFP registered used by executable, not object file but the problem there was that some parts of the binary were soft- and some were hard-float. I have a single C++ file to compile...

我想念哪些参数无法使用 -march=armv7-a -mthumb-interwork -mfloat-abi=softfp -mfpu=neon 进行编译?

What parameter(s) I miss to be able to compile with -march=armv7-a -mthumb-interwork -mfloat-abi=softfp -mfpu=neon?

当我在命令行中明确使用 -mfloat-abi=softfp 禁止 VFP 寄存器参数时,错误怎么可能与 VFP 寄存器参数有关?

How is it possible that the error is about VFP register arguments while I explicitly have -mfloat-abi=softfp in the command line which prohibits VFP register arguments?

谢谢!

为了记录,hello_world.cpp 包含以下内容:

For the records, hello_world.cpp contains the following:

#include <iostream>

int main()
{
  std::cout << "Hello, world!" << std::endl;
  return 0;
}

推荐答案

您需要另一个具有相应多库支持的编译器.您可以使用下一个命令检查多库支持.

You need another compiler with corresponding multilib support. You can check multilib support with next command.

arm-none-eabi-gcc -print-multi-lib
.;
thumb;@mthumb
fpu;@mfloat-abi=hard
armv6-m;@mthumb@march=armv6s-m
armv7-m;@mthumb@march=armv7-m
armv7e-m;@mthumb@march=armv7e-m
armv7-ar/thumb;@mthumb@march=armv7
cortex-m7;@mthumb@mcpu=cortex-m7
armv7e-m/softfp;@mthumb@march=armv7e-m@mfloat-abi=softfp@mfpu=fpv4-sp-d16
armv7e-m/fpu;@mthumb@march=armv7e-m@mfloat-abi=hard@mfpu=fpv4-sp-d16
armv7-ar/thumb/softfp;@mthumb@march=armv7@mfloat-abi=softfp@mfpu=vfpv3-d16
armv7-ar/thumb/fpu;@mthumb@march=armv7@mfloat-abi=hard@mfpu=vfpv3-d16
cortex-m7/softfp/fpv5-sp-d16;@mthumb@mcpu=cortex-m7@mfloat-abi=softfp@mfpu=fpv5-sp-d16
cortex-m7/softfp/fpv5-d16;@mthumb@mcpu=cortex-m7@mfloat-abi=softfp@mfpu=fpv5-d16
cortex-m7/fpu/fpv5-sp-d16;@mthumb@mcpu=cortex-m7@mfloat-abi=hard@mfpu=fpv5-sp-d16
cortex-m7/fpu/fpv5-d16;@mthumb@mcpu=cortex-m7@mfloat-abi=hard@mfpu=fpv5-d16
https://stackoverflow.com/questions/37418986/how-to-interpret-the-output-of-gcc-print-multi-lib

如何解释gcc的输出-print-multi-lib使用此配置 gcc -mfloat-abi=hard 不仅会使用 FPU 指令构建文件,还会将它们与相应的库链接,避免 "X 使用 VFP 寄存器参数,Y 没有" 错误.

How to interpret the output of gcc -print-multi-lib With this configuration gcc -mfloat-abi=hard not only will build your files using FPU instructions but also link them with corresponding libs, avoiding "X uses VFP register arguments, Y does not" error.

上述 -print-multi-lib 输出由 gcc 与 这个补丁--with-multilib-list=armv6-m,armv7,armv7-m,armv7e-m,armv7-r,armv7-a,cortex-m7 配置选项.如果您有兴趣使用 Cortex-A 系列 multilib 支持构建自己的 gcc,只需对任何 arm*-*-* 使用 --with-multilib-list=aprofile 配置选项代码> 没有任何补丁的目标(at用 gcc-6.2.0 列出).

The above-mentioned -print-multi-lib output produced by gcc with this patch and --with-multilib-list=armv6-m,armv7,armv7-m,armv7e-m,armv7-r,armv7-a,cortex-m7 configuration option. If you are interested in building your own gcc with Cortex-A series multilib support, just use --with-multilib-list=aprofile configuration option for any arm*-*-* target without any patches (at list with gcc-6.2.0).

这篇关于如何使用单个 GCC(交叉)编译器(交叉)编译为 ARM 硬浮点和软浮点(softfp)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆