Sign in to follow this  
jake_Ghost

weird linker errors with std::strings

Recommended Posts

I have multiple arrars of string for different groups of sound paths...
MissSound[0] = "Data/Sound/Combat/MissSwings/MissWhoosh1Handed.wav";
	MissSound[1] = "Data/Sound/Combat/MissSwings/MissWhoosh2Handed.wav";

	ParrySound[0] = "Data/Sound/Combat/ParrySounds/1hParryMetalHitMetal.wav";
	ParrySound[1] = "Data/Sound/Combat/ParrySounds/1hParryMetalHitMetalCritical.wav";
	ParrySound[2] = "Data/Sound/Combat/ParrySounds/1hParryMetalHitWood.wav";
	ParrySound[3] = "Data/Sound/Combat/ParrySounds/1hParryMetalHitWoodCritical.wav";
	ParrySound[4] = "Data/Sound/Combat/ParrySounds/1hParryWoodHitMetal.wav";
	ParrySound[5] = "Data/Sound/Combat/ParrySounds/1hParryWoodHitMetalCritical.wav";
	ParrySound[6] = "Data/Sound/Combat/ParrySounds/1hParryWoodhitWood.wav";
	ParrySound[7] = "Data/Sound/Combat/ParrySounds/1hParryWoodhitWoodCritical.wav";
	ParrySound[8] = "Data/Sound/Combat/ParrySounds/2hParryMetalHitMetal.wav";
	ParrySound[9] = "Data/Sound/Combat/ParrySounds/2hParryMetalHitMetalCritical.wav";
	ParrySound[10] = "Data/Sound/Combat/ParrySounds/2hParryMetalHitWood.wav";
	ParrySound[11] = "Data/Sound/Combat/ParrySounds/2hParryMetalHitWoodCritical.wav";
	ParrySound[12] = "Data/Sound/Combat/ParrySounds/2hParryWoodHitMetal.wav";
	ParrySound[13] = "Data/Sound/Combat/ParrySounds/2hParryWoodHitMetalCritical.wav";
	ParrySound[14] = "Data/Sound/Combat/ParrySounds/2hParryWoodHitWood.wav";
	ParrySound[15] = "Data/Sound/Combat/ParrySounds/2hParryWoodHitWoodCritical.wav";

	BlockSound[0] = "Data/Sound/Combat/Shields/MetalShieldBlock1.wav";
	BlockSound[1] = "Data/Sound/Combat/Shields/MetalShieldBlock2.wav";
	BlockSound[2] = "Data/Sound/Combat/Shields/MetalShieldBlock3.wav";
	BlockSound[3] = "Data/Sound/Combat/Shields/WoodenShieldBlock1.wav";
	BlockSound[4] = "Data/Sound/Combat/Shields/WoodenShieldBlock2.wav";
	BlockSound[5] = "Data/Sound/Combat/Shields/WoodenShieldBlock3.wav";

	HitSound[0] = "Data/Sound/Combat/Axe2H/m2hAxeHitChain1a.wav";
	HitSound[1] = "Data/Sound/Combat/Axe2H/m2hAxeHitChain1b.wav";
	HitSound[2] = "Data/Sound/Combat/Axe2H/m2hAxeHitChain1c.wav";
	HitSound[3] = "Data/Sound/Combat/Axe2H/m2hAxeHitChainCrit.wav";
	HitSound[4] = "Data/Sound/Combat/Axe2H/m2hAxeHitFlesh1a.wav";
	HitSound[5] = "Data/Sound/Combat/Axe2H/m2hAxeHitFlesh1b.wav";
	HitSound[6] = "Data/Sound/Combat/Axe2H/m2hAxeHitFlesh1c.wav";
	HitSound[7] = "Data/Sound/Combat/Axe2H/m2hAxeHitFleshCrit.wav";
	HitSound[8] = "Data/Sound/Combat/Axe2H/m2hAxeHitMetalShield1a.wav";
	HitSound[9] = "Data/Sound/Combat/Axe2H/m2hAxeHitMetalShield1b.wav";
	HitSound[10] = "Data/Sound/Combat/Axe2H/m2hAxeHitMetalShield1c.wav";
	HitSound[11] = "Data/Sound/Combat/Axe2H/m2hAxeHitMetalShieldCrit.wav";
	HitSound[12] = "Data/Sound/Combat/Axe2H/m2hAxeHitMetalWeapon1a.wav";
	HitSound[13] = "Data/Sound/Combat/Axe2H/m2hAxeHitMetalWeaponCrit.wav";
	HitSound[14] = "Data/Sound/Combat/Axe2H/m2hAxeHitPlate1a.wav";
	HitSound[15] = "Data/Sound/Combat/Axe2H/m2hAxeHitPlate1b.wav";
	HitSound[16] = "Data/Sound/Combat/Axe2H/m2hAxeHitPlate1c.wav";
	HitSound[17] = "Data/Sound/Combat/Axe2H/m2hAxeHitPlateCrit.wav";
	HitSound[18] = "Data/Sound/Combat/Axe2H/m2hAxeHitStone1A.wav";
	HitSound[19] = "Data/Sound/Combat/Axe2H/m2hAxeHitStone1B.wav";
	HitSound[20] = "Data/Sound/Combat/Axe2H/m2hAxeHitStone1C.wav";
	HitSound[21] = "Data/Sound/Combat/Axe2H/m2hAxeHitStone1CritA.wav";
	HitSound[22] = "Data/Sound/Combat/Axe2H/m2hAxeHitWood1A.wav";
	HitSound[23] = "Data/Sound/Combat/Axe2H/m2hAxeHitWood1B.wav";
	HitSound[24] = "Data/Sound/Combat/Axe2H/m2hAxeHitWood1C.wav";
	HitSound[25] = "Data/Sound/Combat/Axe2H/m2hAxeHitWood1CritA.wav";

	WeaponSwing[0] = "Data/Sound/Combat/WeaponSwings/mWooshLarge1.wav";
	WeaponSwing[1] = "Data/Sound/Combat/WeaponSwings/mWooshLarge2.wav";
	WeaponSwing[2] = "Data/Sound/Combat/WeaponSwings/mWooshLarge3.wav";
	WeaponSwing[3] = "Data/Sound/Combat/WeaponSwings/mWooshLargeCrit.wav";

	CharAttack[0] = "Data/Sound/Character/NightElf/NightElfMale/NightElfMaleAttackA.wav";
	CharAttack[1] = "Data/Sound/Character/NightElf/NightElfMale/NightElfMaleAttackB.wav";
	CharAttack[2] = "Data/Sound/Character/NightElf/NightElfMale/NightElfMaleAttackC.wav";

	CharWound[0] = "Data/Sound/Character/NightElf/NightElfMale/NightElfMaleWoundA.wav";
	CharWound[1] = "Data/Sound/Character/NightElf/NightElfMale/NightElfMaleWoundB.wav";
	CharWound[2] = "Data/Sound/Character/NightElf/NightElfMale/NightElfMaleWoundC.wav";
	CharWound[3] = "Data/Sound/Character/NightElf/NightElfMale/NightElfMaleWoundCrit.wav";

when i try and compile my game i get these errors...
------ Build started: Project: Maia, Configuration: Debug Win32 ------

Compiling...
Sound.cpp
Linking...
Maia.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * CharWound" (?CharWound@@3PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Hero.obj
Maia.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * MissSound" (?MissSound@@3PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Hero.obj
Maia.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * WeaponSwing" (?WeaponSwing@@3PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Hero.obj
Maia.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * ParrySound" (?ParrySound@@3PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Hero.obj
Maia.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * CharAttack" (?CharAttack@@3PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Hero.obj
Maia.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * BlockSound" (?BlockSound@@3PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Hero.obj
Maia.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * HitSound" (?HitSound@@3PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Hero.obj
Sound.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * CharWound" (?CharWound@@3PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Hero.obj
Sound.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * MissSound" (?MissSound@@3PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Hero.obj
Sound.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * WeaponSwing" (?WeaponSwing@@3PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Hero.obj
Sound.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * ParrySound" (?ParrySound@@3PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Hero.obj
Sound.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * CharAttack" (?CharAttack@@3PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Hero.obj
Sound.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * BlockSound" (?BlockSound@@3PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Hero.obj
Sound.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * HitSound" (?HitSound@@3PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Hero.obj
cUI.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * CharWound" (?CharWound@@3PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Hero.obj
cUI.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * MissSound" (?MissSound@@3PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Hero.obj
cUI.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * WeaponSwing" (?WeaponSwing@@3PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Hero.obj
cUI.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * ParrySound" (?ParrySound@@3PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Hero.obj
cUI.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * CharAttack" (?CharAttack@@3PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Hero.obj
cUI.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * BlockSound" (?BlockSound@@3PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Hero.obj
cUI.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * HitSound" (?HitSound@@3PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Hero.obj
cUI.obj : warning LNK4217: locally defined symbol ??0FTGLBitmapFont@@QAE@PBD@Z (public: __thiscall FTGLBitmapFont::FTGLBitmapFont(char const *)) imported in function _$E22
cUI.obj : warning LNK4217: locally defined symbol ??1FTGLBitmapFont@@UAE@XZ (public: virtual __thiscall FTGLBitmapFont::~FTGLBitmapFont(void)) imported in function "public: virtual void * __thiscall FTGLBitmapFont::`scalar deleting destructor'(unsigned int)" (??_GFTGLBitmapFont@@UAEPAXI@Z)
.\Debug/Maia.exe : fatal error LNK1169: one or more multiply defined symbols found

Build log was saved at "file://d:\Final Project\Debug\BuildLog.htm"
Maia - 22 error(s), 2 warning(s)


---------------------- Done ----------------------

    Build: 0 succeeded, 1 failed, 0 skipped

anyone know why I get these errors? Jake

Share this post


Link to post
Share on other sites
Can you delete Hero.obj, and rebuild?

Apparently you've defined those strings somewhere already...

Or: are those strings defined in an .h file that you include more than once?

Share this post


Link to post
Share on other sites
What about the arrays themselves? Are they declared in a header file? This problem SOUNDS like a classic case of putting global variable declarations in a header file, but it still could be something else.

Share this post


Link to post
Share on other sites
As a side note: it's really unnecessary to type all that stuff out in the code, and actually a bad idea (it will increase the coupling between code and resources; it will also require you to re-build if you change a single resource file).

You should have dynamic arrays instead of static (think std::vector), and load up the strings from a file at runtime. So you would put all those filenames in a single 'resource file', which the game would look at, and load all files listed therein.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this