【问题标题】:Why is __float128 not supported?为什么不支持 __float128?
【发布时间】:2021-12-12 22:12:19
【问题描述】:

所以我尝试使用__float128-type 在 C 中进行非常精确的数学运算。

我的代码如下所示:

#include <stdio.h>

int main() {
    __float128 num;
}

我尝试在没有任何选项的情况下编译它:

gcc -o test test.c

我得到的错误是:

test.c:4:5: error: __float128 is not supported on this target

我的 gcc 是在 x86 Macbook 上使用 Homebrew 安装的。

【问题讨论】:

  • 库不仅仅是标题。标头只是库中内容的列表。它不是真正的图书馆。
  • 您使用的是 Intel (x86) Mac 还是 Apple Silicon (ARM) Mac?
  • @JosephSible-ReinstateMonica 我使用的是 2019 年的 x86 MacBook Air。
  • 等一下。 Libquadmath 不提供 __float128;这取决于它已经可用。 libquadmath 有什么你实际使用的东西吗?如果您只删除 #include &lt;quadmath.h&gt; 会发生什么?
  • @JosephSible-ReinstateMonica test.c:4:5: error: __float128 is not supported on this target

标签: c gcc


【解决方案1】:

我的 gcc 是在 x86 Macbook 上使用 Homebrew 安装的。

您可能已经这样做了,但是您运行以编译您的测试程序的gcc 实际上是伪装成 GCC 的 Apple clang,如果您这样做了gcc -v,您会看到。 Apple clang 不支持 __float128,但真正的 GCC 支持。执行/usr/local/bin/gcc-11 -o test test.c 使用您安装的真正的GCC,然后它应该可以编译成功。

【讨论】:

  • 现在它告诉我In file included from test.c:1: /usr/local/Cellar/gcc/11.2.0/lib/gcc/11/gcc/x86_64-apple-darwin21/11.2.0/include-fixed/stdio.h:78:10: fatal error: _stdio.h: No such file or directory
  • @gurkensaas 尝试重做xcode-select --install
  • @gurkensaas 要使用 libquadmath,仅包含标头是不够的。您还需要在 GCC 命令行末尾添加-lquadmath
  • @gurkensaas 您不能覆盖字符串文字。你想改用char str[11]; quadmath_snprintf(str, 11, "%Qg", num);
  • @gurkensaas 但请不要在参数中逐字指定11,使用sizeof str。否则,str 的大小更改将要求您至少在两个位置编辑该值,其中一些您可能会忘记更新。另请参阅DRY principle
猜你喜欢
  • 1970-01-01
  • 2011-03-17
  • 2018-07-21
  • 2013-01-04
  • 2017-10-07
  • 2018-08-24
  • 2011-09-16
  • 2016-09-11
  • 2012-09-29
相关资源
最近更新 更多