Please help with STL

K

Kostatus

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<unsigned short,int,struct
std::less<unsigned short>,class std::allocator<int> > siMap"
(?siMap@@3V?$map@GHU?$less@G@std@@V?$allocator@H@2@@std@@A) already defined
in Digger.obj
DungOperations.obj : error LNK2005: "class std::map<unsigned
short,int,struct std::less<unsigned short>,class std::allocator<int> >
siMap" (?siMap@@3V?$map@GHU?$less@G@std@@V?$allocator@H@2@@std@@A) already
defined in Digger.obj
Fov.obj : error LNK2005: "class std::map<unsigned short,int,struct
std::less<unsigned short>,class std::allocator<int> > siMap"
(?siMap@@3V?$map@GHU?$less@G@std@@V?$allocator@H@2@@std@@A) already defined
in Digger.obj
Game.obj : error LNK2005: "class std::map<unsigned short,int,struct
std::less<unsigned short>,class std::allocator<int> > siMap"
(?siMap@@3V?$map@GHU?$less@G@std@@V?$allocator@H@2@@std@@A) already defined
in Digger.obj
Global.obj : error LNK2005: "class std::map<unsigned short,int,struct
std::less<unsigned short>,class std::allocator<int> > siMap"
(?siMap@@3V?$map@GHU?$less@G@std@@V?$allocator@H@2@@std@@A) already defined
in Digger.obj
Io_Obj : error LNK2005: "class std::map<unsigned short,int,struct
std::less<unsigned short>,class std::allocator<int> > siMap"
(?siMap@@3V?$map@GHU?$less@G@std@@V?$allocator@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?
 
A

Andrey Tarasevich

Kostatus said:
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<unsigned short,int,struct
std::less<unsigned short>,class std::allocator<int> > siMap"
(?siMap@@3V?$map@GHU?$less@G@std@@V?$allocator@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?
...

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<unsigned short, int> siMap;

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

std::map<unsigned short, int> siMap;
 

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