Problem with GMP and a user defined namespace

Marc Glisse marc.glisse at normalesup.org
Mon Jul 20 17:36:01 CEST 2009


On Mon, 20 Jul 2009, Christopher Creutzig wrote:

> While I agree that putting new namespaces around some unsuspecting code
> is a bad idea, this reason should not be one. By the rules of Koenig
> lookup, the GMP::operator<< will be found if one of the operands has a
> type defined in the GMP namespace.

And the linker will look for a definition of 
GMP::operator<<(std::ostream&, GMP::__mpz_struct const*) (mangled as 
_ZN3GMPlsERSoPKNS_12__mpz_structE by g++) whereas libgmpxx.so (or .a) only 
provides a definition for ::operator<<(std::ostream&, __mpz_struct const*) 
(mangled as _ZlsRSoPK12__mpz_struct).

That is, you can't use gmp as is in a namespace, you'd have to modify gmp 
before compiling it, or at least provide aliases for symbols in libgmpxx.

-- 
Marc Glisse


More information about the gmp-discuss mailing list