Using C++ output functions

Wolfram Wiesemann wolfram.wiesemann at
Wed Feb 14 12:51:59 CET 2007

I guess this problem is less related to GMP than to general C++ compilation,
but it would be very helpful if someone could nevertheless explain me what
to do.

When compiling the following simple program

#include <gmp.h>
#include <gmpxx.h>
#include <iostream>

using namespace std;

int main() {
  mpf_class f;
  f = 3.5 * 2.2;
  cout << f;
  return 0;

with the following command

g++ -static -lgmp -lgmpxx

I get the following error message:

/usr/local/lib/libgmpxx.a(osmpf.o): In function
`operator<<(std::basic_ostream<char, std::char_traits<char> >&, __mpf_struct
const*)': undefined reference to `__gmp_doprnt_mpf2' undefined reference to `__gmp_asprintf_final'
/usr/local/lib/libgmpxx.a(osfuns.o):(.rodata+0x4): undefined reference to
/usr/local/lib/libgmpxx.a(osfuns.o):(.rodata+0x8): undefined reference to
collect2: ld returned 1 exit status

If I remove the line "cout << f" from the code, everything works fine. I
have used the "--enable-cxx" parameter during the make process, so that
should be okay.

Can anybody give me a hint what I need to do?


-------------- next part --------------
An HTML attachment was scrubbed...

More information about the gmp-discuss mailing list