Problem with GMP and a user defined namespace

Marc Glisse marc.glisse at
Fri Jul 17 17:08:13 CEST 2009

On Fri, 17 Jul 2009, whatever at wrote:

> Due to the fact that existing code which I am using, includes gmp.h and 
> gmpxx.h inside a new defined namespace I need to do the same in my code:
> namespace GMP{
> #include "gmp.h"
> #include "gmpxx.h"
> }

This is completely unsupported and doesn't sound like a good idea. 
Besides, if you are using a library that already does something like that, 
how come you need to do it yourself?

> #include <iostream>
> using namespace std;
> namespace GMP{
> #include "gmp.h"
> #include "gmpxx.h"
> }

At the very least, before those #includes, you want to include (in the 
global namespace) all the standard headers that gmp.h and gmpxx.h include.

> Am I missing something here? I just don't know where to look any more or even 
> what I should be looking for. All my research in the internet explained to me 
> that, yes, I can create namespaces around a library I am using to reduce 
> effects of what happens inside the library.

Don't know where you found such wrong statements (or what accompanying 
recommendation you missed).

This namespace thing makes the compiled gmpxx inadequate since it is 
defining say operator<< and not GMP::operator<<.

Marc Glisse

More information about the gmp-discuss mailing list