Quadruple precision in G++ 4.6.3 Linux using quadmath
Asked Answered
H

1

7

I've tried 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 this command

g++ test.cpp -o test

But I got 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?

Halfhearted answered 26/11, 2012 at 19:22 Comment(0)
B
6

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
Bell answered 26/11, 2012 at 19:38 Comment(4)
Thanks. It works for me.[code] g++ test.cpp -o test -lquadmath ./test 1.000000Halfhearted
I am using GCC 5.3.0 and this workaround does not work.Rms
this worked for me, and adding the option -lquadmath to the gcc command got my C programs to work as well.Distaff
where do you include extern "C" { #include "quadmath.h" } can you please provide more details in your answer? ThanksSignificant

© 2022 - 2024 — McMap. All rights reserved.