newbie: error: namespace `__gnu_cxx' undeclared

M

makwak

when I compile the following program under my linux:

namespace std {
using namespace __gnu_cxx;
}

main() {
};


I got the following error message:

prompt# /usr/local/gcc-3.2.3/bin/gcc p1.cpp
p1.cpp:9: namespace `__gnu_cxx' undeclared

what file should I include ?

greetings
 
R

Rolf Magnus

makwak said:
when I compile the following program under my linux:

namespace std {

You're not supposed to put anything into namespace std yourself.
using namespace __gnu_cxx;

There is no namespace __gnu_cxx, if it's not defined anywhere.
}

main() {
};


I got the following error message:

prompt# /usr/local/gcc-3.2.3/bin/gcc p1.cpp
p1.cpp:9: namespace `__gnu_cxx' undeclared

what file should I include ?

Whatever file you need. You didn't use anything from that namespace anyway,
so it's enough to just leave out the using directive. Then you also won't
need to include any header.
 
C

Chris Jefferson

makwak said:
when I compile the following program under my linux:

namespace std {
using namespace __gnu_cxx;
}

main() {
};


I got the following error message:

prompt# /usr/local/gcc-3.2.3/bin/gcc p1.cpp
p1.cpp:9: namespace `__gnu_cxx' undeclared

what file should I include ?

I think what you are trying to do is to pull the g++ extensions into the
std namespace.

In actual fact this code should tell you std isn't declared either
(thats a g++ bug..)

I should warn you that even when you've included the relevant files with
bits of the __gnu_cxx namespace (which contains various extensions and
internals of g++'s implementation of the c++ standard library) the code
you are trying to write will quite likely break something. Why would you
want to do such a thing?

Chris
 
S

Stefan Strasser

makwak said:
when I compile the following program under my linux:

namespace std {
using namespace __gnu_cxx;
}

main() {
};


I got the following error message:

prompt# /usr/local/gcc-3.2.3/bin/gcc p1.cpp
p1.cpp:9: namespace `__gnu_cxx' undeclared

what file should I include ?

depends on which of the g++ extensions you want to use.
e.g.
#include <ext/hash_map>

but I'd rather use a namespace alias than using it into namespace std:

namespace gnu = __gnu_cxx;
 
R

Rolf Magnus

Chris said:
I think what you are trying to do is to pull the g++ extensions into the
std namespace.

In actual fact this code should tell you std isn't declared either

No, it shouldn't.
(thats a g++ bug..)

Some rather old versions of g++ (< 3.0) treated namespace std as synonym for
the global namespace.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top