Please help with STL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kostatus

    Please help with STL

    I'm trying to use STL maps with VC++ 6 .
    I already have 2 different types of maps working fine,
    but a new one that I've just added refuses to work
    Instead of some reasonable explanation the compiler gives
    me the following mumble-jumble:

    Dungeon.obj : error LNK2005: "class std::map<unsign ed short,int,struc t
    std::less<unsig ned short>,class std::allocator< int> > siMap"
    (?siMap@@3V?$ma p@GHU?$less@G@s td@@V?$allocato r@H@2@@std@@A) already defined
    in Digger.obj
    DungOperations. obj : error LNK2005: "class std::map<unsign ed
    short,int,struc t std::less<unsig ned short>,class std::allocator< int> >
    siMap" (?siMap@@3V?$ma p@GHU?$less@G@s td@@V?$allocato r@H@2@@std@@A) already
    defined in Digger.obj
    Fov.obj : error LNK2005: "class std::map<unsign ed short,int,struc t
    std::less<unsig ned short>,class std::allocator< int> > siMap"
    (?siMap@@3V?$ma p@GHU?$less@G@s td@@V?$allocato r@H@2@@std@@A) already defined
    in Digger.obj
    Game.obj : error LNK2005: "class std::map<unsign ed short,int,struc t
    std::less<unsig ned short>,class std::allocator< int> > siMap"
    (?siMap@@3V?$ma p@GHU?$less@G@s td@@V?$allocato r@H@2@@std@@A) already defined
    in Digger.obj
    Global.obj : error LNK2005: "class std::map<unsign ed short,int,struc t
    std::less<unsig ned short>,class std::allocator< int> > siMap"
    (?siMap@@3V?$ma p@GHU?$less@G@s td@@V?$allocato r@H@2@@std@@A) already defined
    in Digger.obj
    IO.obj : error LNK2005: "class std::map<unsign ed short,int,struc t
    std::less<unsig ned short>,class std::allocator< int> > siMap"
    (?siMap@@3V?$ma p@GHU?$less@G@s td@@V?$allocato r@H@2@@std@@A) already defined
    in Digger.obj
    Debug/game.exe : fatal error LNK1169: one or more multiply defined symbols
    found
    Error executing link.exe.

    I have no idea how to fix this or interpret it and I do not
    want to replace the map with a usual array unless it's
    completely necessary. Can anyone help me?


  • Andrey Tarasevich

    #2
    Re: Please help with STL

    Kostatus wrote:[color=blue]
    > I'm trying to use STL maps with VC++ 6 .
    > I already have 2 different types of maps working fine,
    > but a new one that I've just added refuses to work
    > Instead of some reasonable explanation the compiler gives
    > me the following mumble-jumble:
    > ...
    > Dungeon.obj : error LNK2005: "class std::map<unsign ed short,int,struc t
    > std::less<unsig ned short>,class std::allocator< int> > siMap"
    > (?siMap@@3V?$ma p@GHU?$less@G@s td@@V?$allocato r@H@2@@std@@A) already defined
    > in Digger.obj
    > ...
    > I have no idea how to fix this or interpret it and I do not
    > want to replace the map with a usual array unless it's
    > completely necessary. Can anyone help me?
    > ...[/color]

    You have more than one definition for object 'siMap' in your program,
    which is a violation of ODR (One Definition Rule). Most common reason
    for this error is putting an object definition into header file and then
    including this header file in multiple translation units.

    Did you put the definition of 'siMap' into a header file? If so, move it
    to some implementation file instead, leaving only a non-defining
    _declaration_ of this object in the header file.

    For example, header file should contain something like this

    extern std::map<unsign ed short, int> siMap;

    and one (and only one of implementation files) should contain something
    like this

    std::map<unsign ed short, int> siMap;

    --
    Best regards,
    Andrey Tarasevich
    Brainbench C and C++ Programming MVP

    Comment

    Working...