newbie: error: namespace `__gnu_cxx' undeclared

Discussion in 'C++' started by makwak, Mar 8, 2005.

  1. makwak

    makwak Guest

    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
    makwak, Mar 8, 2005
    #1
    1. Advertising

  2. makwak

    Rolf Magnus Guest

    makwak wrote:

    > 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.
    Rolf Magnus, Mar 8, 2005
    #2
    1. Advertising

  3. makwak wrote:
    > 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
    Chris Jefferson, Mar 8, 2005
    #3
  4. makwak schrieb:
    > 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;
    Stefan Strasser, Mar 9, 2005
    #4
  5. makwak

    Rolf Magnus Guest

    Chris Jefferson wrote:

    > makwak wrote:
    >> 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


    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.
    Rolf Magnus, Mar 9, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Romeo Disca
    Replies:
    1
    Views:
    2,601
    Dennis E. Hamilton
    Aug 31, 2003
  2. Replies:
    6
    Views:
    716
  3. aaragon
    Replies:
    4
    Views:
    4,013
    aaragon
    Oct 30, 2007
  4. veryhotsausage
    Replies:
    1
    Views:
    1,776
    veryhotsausage
    Jul 4, 2008
  5. Carfield Yim
    Replies:
    5
    Views:
    489
Loading...

Share This Page