使用Quadmath的G ++ 4.6.3 Linux中的四倍精度 [英] Quadruple precision in G++ 4.6.3 Linux using quadmath

查看:154
本文介绍了使用Quadmath的G ++ 4.6.3 Linux中的四倍精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试执行代码

#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.

如何解决该问题?

推荐答案

我看到了相同的行为:

~/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

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

One workaround is to include the header using this pattern instead:

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

之后:

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

这篇关于使用Quadmath的G ++ 4.6.3 Linux中的四倍精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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