Quadruple precision in G++ 4.6.3 Linux using quadmath

两盒软妹~` 提交于 2019-12-19 06:57:42

问题


I try to execute the code

#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;
}

with commands

g++ test.cpp -o test

I get the error:

/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

The version is:

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.

How can I fix the problem?


回答1:


I see the same behaviour:

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

after which:

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


来源:https://stackoverflow.com/questions/13571621/quadruple-precision-in-g-4-6-3-linux-using-quadmath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!