Error in linking with mpz_class in ostream

Georg Lippold georg.lippold at
Thu Oct 9 06:53:53 CEST 2008


I'm trying to represent a mpz_class object as a string. Therefore, I 
coded the following few lines:

#include <gmpxx.h>
#include <cstdio>
#include <sstream>
#include <bits/stringfwd.h>
using namespace std;

int main(int argc, char** argv) {
mpz_class a;
a = 1234;
ostringstream out;
out << a << endl;


The code compiles fine, however the linker fails with the following message:

./src/main.o: In function `std::basic_ostream<char, 
std::char_traits<char> >& operator<< <__mpz_struct 
[1]>(std::basic_ostream<char, std::char_traits<char> >&, 
__gmp_expr<__mpz_struct [1], __mpz_struct [1]> const&)':
/usr/include/gmpxx.h:2020: undefined reference to 
`operator<<(std::basic_ostream<char, std::char_traits<char> >&, 
__mpz_struct const*)'

I think that my code is comparable to the example on

As I'm not a C++ guru, maybe I'm doing something wrong. Could you please 
tell me how to do this correctly?

Thanks & Regards,


More information about the gmp-bugs mailing list