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

查看:586
本文介绍了如何使用单个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

成功,没有任何错误.

如果我使用-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;
}

推荐答案

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

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 通过这种配置,gcc -mfloat-abi=hard不仅将使用FPU指令来构建文件,而且还会将它们与相应的库链接,从而避免错误.

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.

gcc使用-print-multi-lib输出>此补丁程序--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配置选项(

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天全站免登陆