四精度在G ++ 4.6.3 Linux中使用quadmath(Quadruple precisio

2019-07-04 03:53发布

我尝试执行代码

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

我该如何解决这一问题?

Answer 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


文章来源: Quadruple precision in G++ 4.6.3 Linux using quadmath