【问题标题】:Quadruple precision in G++ 4.6.3 Linux using quadmathG++ 4.6.3 Linux 中使用 quadmath 的四倍精度
【发布时间】:2012-11-14 07:54:35
【问题描述】:

我已经尝试执行代码

#include <quadmath.h>
#include <iostream>
int main()
{
  char* y = new char[1000];
  quadmath_snprintf(y, 1000, "%Qf", 1.0q);
  std::cout << y << std::endl;
  return 0;
}

用这个命令

g++ test.cpp -o test

但我得到了错误:

/tmp/cctqto7E.o: In function `main':
test.cpp:(.text+0x51): undefined reference to `quadmath_snprintf(char*, unsigned int, char const*, ...)'
collect2: ld returned 1 exit status

版本是:

g++ --version
g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

我该如何解决这个问题?

【问题讨论】:

    标签: c++ linux ubuntu quadruple-precision


    【解决方案1】:

    我看到了同样的行为:

    ~/coding/q$ g++ test.cpp -lquadmath
    /tmp/ccYdHwL5.o: In function `main':
    test.cpp:(.text+0x51): undefined reference to `quadmath_snprintf(char*, unsigned int, char const*, ...)'
    collect2: ld returned 1 exit status
    

    一种解决方法是使用此模式包含标题:

    extern "C" {
    #include "quadmath.h"
    }
    

    之后:

    ~/coding/q$ g++ test.cpp -lquadmath
    ~/coding/q$ ./a.out 
    1.000000
    

    【讨论】:

    • 谢谢。它对我有用。[code] g++ test.cpp -o test -lquadmath ./test 1.000000
    • 我使用的是 GCC 5.3.0,但此解决方法不起作用。
    • 这对我有用,在 gcc 命令中添加选项 -lquadmath 可以让我的 C 程序也能正常工作。
    • 你在哪里包括extern "C" { #include "quadmath.h" }你能在你的回答中提供更多细节吗?谢谢
    猜你喜欢
    • 1970-01-01
    • 2020-03-24
    • 1970-01-01
    • 2017-01-23
    • 1970-01-01
    • 1970-01-01
    • 2022-11-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多