#438 Impossible to use STL 'map'

Known_bugs
closed-invalid
Earnie Boyd
MinGW (57)
2003-09-27
2003-09-26
Sylvain Boucher
No

Hi,

I use MinGW under WindowsXP
with gcc v 3.2.3 (mingw special 20030504-1)
ld v 2.13.90 20030111

I try to compile the following code:
# include <map>

using namespace std;

int main ()
{

map<int, int> environ;

environ [4] = 3;

return 0;
}

And I get an error while linking:
c:/tmp/ccY5aaaa.o(.text+0x30):env.cpp: undefined
reference to `__p__environ()'

Regards

Discussion

  • Danny Smith
    Danny Smith
    2003-09-26

    Logged In: YES
    user_id=11494

    The problem is your use of the name 'environ'. This steps on
    the C runtime global 'environ' name defined in stdlib.h.
    If you change the name (or put in a different namespace than
    global) it should work. But yes, there are namespace
    problems in C headers.

    Dann

     
  • Earnie Boyd
    Earnie Boyd
    2003-09-27

    • status: open --> closed-invalid
     
  • Earnie Boyd
    Earnie Boyd
    2003-09-27

    Logged In: YES
    user_id=15438

    Namespace collision with environ variable. User must change
    his code.

     
  • Logged In: YES
    user_id=875015

    Hi,

    Thanks for the quick answer, I was able to solve the
    problem. However what surprised me, is that the very same
    code mentioned above did compile with other platform, with
    same gcc version...

    Regards

    Sylvain