找到一个或多个乘法定义的符号,错误LNK1169 C ++(One or more multiply defined symbols found, error LNK1169 C++)

编程入门 行业动态 更新时间:2024-10-27 19:17:53
找到一个或多个乘法定义的符号,错误LNK1169 C ++(One or more multiply defined symbols found, error LNK1169 C++)

很抱歉缺少描述性标题。 我收到一个错误“找到一个或多个多重定义的符号”; 更具体地说,我得到了46个。 一个用于我的头文件/源文件中的每个函数。 使用Visual Studios 2013。

这是相关的源代码:

augments.h

#ifndef AUGMENTS_H_ #define AUGMENTS_H_ namespace Augments { // only used for pass-ins for constructors enum class Weapon_Type { sword }; enum class Head_Type { head }; enum class Body_Type { body }; // the player (Monster) has a head, body and weapon // that augments his abilities. This will mostly // be the thing that draws to the screen for each // augmentation, but more importantly it contains // specific statistics about each one. // So if there was a body that was able to fly, // there would be a bool that denotes this ability. class Head : public Actor { const Head_Type type; public: Head(Head_Type); void Update(float dt); }; class Body : public Actor { const Body_Type type; public: Body(Body_Type); void Update(float dt); }; class Weapon : public Actor { const Weapon_Type type; public: Weapon(Weapon_Type); void Update(float dt); }; } using AugHead = Augments::Head; using AugBody = Augments::Body; using AugWep = Augments::Weapon; #endif

augments.cpp

#include "stdafx.h" #include "Angel.h" #include "Augments.h" #include "LD33.h" Augments::Head::Head(Augments::Head_Type x) : type(x) { switch ( x ) { case Head_Type::head: SetSprite("Images\\head.png"); break; }; }; void Augments::Head::Update(float dt) { SetPosition(Game::thePlayer->GetPosition().X, Game::thePlayer->GetPosition().Y- MathUtil::ScreenToWorld(Vec2i(0,40)).Y); }; Augments::Body::Body(Augments::Body_Type x) : type(x) { switch ( x ) { case Body_Type::body: SetSprite("Images\\body.png"); break; }; } void Augments::Body::Update(float dt) { SetPosition(Game::thePlayer->GetPosition().X, Game::thePlayer->GetPosition().Y); } Augments::Weapon::Weapon(Augments::Weapon_Type x ) : type(x) { switch ( x ) { case Weapon_Type::sword: SetSprite("Images\\weapon.png"); break; } } void Augments::Weapon::Update(float dt) { SetPosition(Game::thePlayer->GetPosition().X, Game::thePlayer->GetPosition().Y- MathUtil::ScreenToWorld(Vec2i(0,-40)).Y); }

monster.h

// monster related #include "Augments.h" #include "Angel.h" #ifndef MONSTER_H_ #define MONSTER_H_ namespace Player { // contains information like health attack etc // but more important body types class Monster : public PhysicsActor { int max_health, curr_health; int attack_damage; Augments::Head* frame_head; Augments::Weapon* frame_weapon; Augments::Body* frame_body; public: void Refresh(float dt); int R_Max_Health() const; int R_Curr_Health() const; int R_Attack_Damage() const; Augments::Head* R_Frame_Head(); Augments::Weapon* R_Frame_Weapon(); Augments::Body* R_Frame_Body(); void Set_Max_Health(int); void Set_Curr_Health(int); void Add_Curr_Health(int); void Set_Attack_Damage(int); // will automatically remove old // actors from the stage and deallocate void Set_Frame_Head(Augments::Head_Type); void Set_Frame_Weapon(Augments::Weapon_Type); void Set_Frame_Body(Augments::Body_Type); Monster(Augments::Head_Type, Augments::Weapon_Type, Augments::Body_Type); }; }; using PlMonster = Player::Monster; #endif

monster.cpp

#include "stdafx.h" #include "Monster.h" #include "Augments.h" #include "Angel.h" void Player::Monster::Refresh(float dt) { }; int Player::Monster::R_Max_Health() const { return max_health; } int Player::Monster::R_Curr_Health() const { return curr_health; } int Player::Monster::R_Attack_Damage() const { return attack_damage; } Augments::Head* Player::Monster::R_Frame_Head() { return frame_head; } Augments::Body* Player::Monster::R_Frame_Body() { return frame_body; } Augments::Weapon* Player::Monster::R_Frame_Weapon() { return frame_weapon; } void Player::Monster::Set_Max_Health(int x) { max_health = x; } void Player::Monster::Set_Curr_Health(int x) { curr_health = x; } void Player::Monster::Add_Curr_Health(int x) { curr_health += x; } void Player::Monster::Set_Attack_Damage(int x) { attack_damage = x; } void Player::Monster::Set_Frame_Head(Augments::Head_Type x) { if ( frame_head != nullptr ) { frame_head->Destroy(); delete frame_head; frame_head = nullptr; } frame_head = new Augments::Head(x); theWorld.Add(frame_head); }; void Player::Monster::Set_Frame_Weapon(Augments::Weapon_Type x) { if ( frame_weapon != nullptr ) { theWorld.Remove(frame_weapon); delete frame_weapon; frame_weapon = nullptr; } frame_weapon = new Augments::Weapon(x); theWorld.Add(frame_weapon); }; void Player::Monster::Set_Frame_Body(Augments::Body_Type x) { if ( frame_body != nullptr ) { theWorld.Remove(frame_body); delete frame_body; frame_body = nullptr; } frame_body = new Augments::Body(x); theWorld.Add(frame_body); }; Player::Monster::Monster(Augments::Head_Type head, Augments::Weapon_Type weapon, Augments::Body_Type body) { frame_body = nullptr; frame_head = nullptr; frame_weapon = nullptr; Set_Frame_Body(body); Set_Frame_Head(head); Set_Frame_Weapon(weapon); }

source.cpp

#include "stdafx.h" #include "LD33.h" #include "Angel.h" int main ( ) { Game::Initialize(); theWorld.StartGame(); theWorld.Destroy(); return 0; }

错误包括以下内容:

Error 43 error LNK2005: "public: int __thiscall Player::Monster::R_Attack_Damage(void)const " (?R_Attack_Damage@Monster@Player@@QBEHXZ) already defined in Augments.obj C:\Users\The Shire\Desktop\ludum_dare\ludumdare33\Code\ClientGame\source.obj ClientGame Error 3 error LNK2005: "public: void __thiscall Player::Monster::Set_Frame_Body(enum Augments::Body_Type)" (?Set_Frame_Body@Monster@Player@@QAEXW4Body_Type@Augments@@@Z) already defined in Augments.obj C:\Users\The Shire\Desktop\ludum_dare\ludumdare33\Code\ClientGame\LD33.obj ClientGame

对于Monster中的每一个函数来说,它几乎都有相似之处。

很抱歉只是倾倒了大量的代码。 我一直试图调试它一段时间,但无法提出任何合理的解决方案。 我有包含保护,我没有看到任何命名空间冲突,并且需要定义的所有内容都在头文件之外。 我在augments.h中找不到会导致这种情况的任何内容。 我也认为它可能是枚举,但用int替换它们也不起作用。

我在想它可能是包含文件的顺序? 哼。 也许在某处有多个源文件,但我不知道如何。 有帮助吗?

Sorry for the lack of a descriptive title. I'm getting an error "one or more multiply defined symbols found"; to be more specific, I'm getting 46 of them. One for each function in my header/source files. Using Visual Studios 2013.

Here is the relevant source code:

augments.h

#ifndef AUGMENTS_H_ #define AUGMENTS_H_ namespace Augments { // only used for pass-ins for constructors enum class Weapon_Type { sword }; enum class Head_Type { head }; enum class Body_Type { body }; // the player (Monster) has a head, body and weapon // that augments his abilities. This will mostly // be the thing that draws to the screen for each // augmentation, but more importantly it contains // specific statistics about each one. // So if there was a body that was able to fly, // there would be a bool that denotes this ability. class Head : public Actor { const Head_Type type; public: Head(Head_Type); void Update(float dt); }; class Body : public Actor { const Body_Type type; public: Body(Body_Type); void Update(float dt); }; class Weapon : public Actor { const Weapon_Type type; public: Weapon(Weapon_Type); void Update(float dt); }; } using AugHead = Augments::Head; using AugBody = Augments::Body; using AugWep = Augments::Weapon; #endif

augments.cpp

#include "stdafx.h" #include "Angel.h" #include "Augments.h" #include "LD33.h" Augments::Head::Head(Augments::Head_Type x) : type(x) { switch ( x ) { case Head_Type::head: SetSprite("Images\\head.png"); break; }; }; void Augments::Head::Update(float dt) { SetPosition(Game::thePlayer->GetPosition().X, Game::thePlayer->GetPosition().Y- MathUtil::ScreenToWorld(Vec2i(0,40)).Y); }; Augments::Body::Body(Augments::Body_Type x) : type(x) { switch ( x ) { case Body_Type::body: SetSprite("Images\\body.png"); break; }; } void Augments::Body::Update(float dt) { SetPosition(Game::thePlayer->GetPosition().X, Game::thePlayer->GetPosition().Y); } Augments::Weapon::Weapon(Augments::Weapon_Type x ) : type(x) { switch ( x ) { case Weapon_Type::sword: SetSprite("Images\\weapon.png"); break; } } void Augments::Weapon::Update(float dt) { SetPosition(Game::thePlayer->GetPosition().X, Game::thePlayer->GetPosition().Y- MathUtil::ScreenToWorld(Vec2i(0,-40)).Y); }

monster.h

// monster related #include "Augments.h" #include "Angel.h" #ifndef MONSTER_H_ #define MONSTER_H_ namespace Player { // contains information like health attack etc // but more important body types class Monster : public PhysicsActor { int max_health, curr_health; int attack_damage; Augments::Head* frame_head; Augments::Weapon* frame_weapon; Augments::Body* frame_body; public: void Refresh(float dt); int R_Max_Health() const; int R_Curr_Health() const; int R_Attack_Damage() const; Augments::Head* R_Frame_Head(); Augments::Weapon* R_Frame_Weapon(); Augments::Body* R_Frame_Body(); void Set_Max_Health(int); void Set_Curr_Health(int); void Add_Curr_Health(int); void Set_Attack_Damage(int); // will automatically remove old // actors from the stage and deallocate void Set_Frame_Head(Augments::Head_Type); void Set_Frame_Weapon(Augments::Weapon_Type); void Set_Frame_Body(Augments::Body_Type); Monster(Augments::Head_Type, Augments::Weapon_Type, Augments::Body_Type); }; }; using PlMonster = Player::Monster; #endif

monster.cpp

#include "stdafx.h" #include "Monster.h" #include "Augments.h" #include "Angel.h" void Player::Monster::Refresh(float dt) { }; int Player::Monster::R_Max_Health() const { return max_health; } int Player::Monster::R_Curr_Health() const { return curr_health; } int Player::Monster::R_Attack_Damage() const { return attack_damage; } Augments::Head* Player::Monster::R_Frame_Head() { return frame_head; } Augments::Body* Player::Monster::R_Frame_Body() { return frame_body; } Augments::Weapon* Player::Monster::R_Frame_Weapon() { return frame_weapon; } void Player::Monster::Set_Max_Health(int x) { max_health = x; } void Player::Monster::Set_Curr_Health(int x) { curr_health = x; } void Player::Monster::Add_Curr_Health(int x) { curr_health += x; } void Player::Monster::Set_Attack_Damage(int x) { attack_damage = x; } void Player::Monster::Set_Frame_Head(Augments::Head_Type x) { if ( frame_head != nullptr ) { frame_head->Destroy(); delete frame_head; frame_head = nullptr; } frame_head = new Augments::Head(x); theWorld.Add(frame_head); }; void Player::Monster::Set_Frame_Weapon(Augments::Weapon_Type x) { if ( frame_weapon != nullptr ) { theWorld.Remove(frame_weapon); delete frame_weapon; frame_weapon = nullptr; } frame_weapon = new Augments::Weapon(x); theWorld.Add(frame_weapon); }; void Player::Monster::Set_Frame_Body(Augments::Body_Type x) { if ( frame_body != nullptr ) { theWorld.Remove(frame_body); delete frame_body; frame_body = nullptr; } frame_body = new Augments::Body(x); theWorld.Add(frame_body); }; Player::Monster::Monster(Augments::Head_Type head, Augments::Weapon_Type weapon, Augments::Body_Type body) { frame_body = nullptr; frame_head = nullptr; frame_weapon = nullptr; Set_Frame_Body(body); Set_Frame_Head(head); Set_Frame_Weapon(weapon); }

source.cpp

#include "stdafx.h" #include "LD33.h" #include "Angel.h" int main ( ) { Game::Initialize(); theWorld.StartGame(); theWorld.Destroy(); return 0; }

Errors include things such as:

Error 43 error LNK2005: "public: int __thiscall Player::Monster::R_Attack_Damage(void)const " (?R_Attack_Damage@Monster@Player@@QBEHXZ) already defined in Augments.obj C:\Users\The Shire\Desktop\ludum_dare\ludumdare33\Code\ClientGame\source.obj ClientGame Error 3 error LNK2005: "public: void __thiscall Player::Monster::Set_Frame_Body(enum Augments::Body_Type)" (?Set_Frame_Body@Monster@Player@@QAEXW4Body_Type@Augments@@@Z) already defined in Augments.obj C:\Users\The Shire\Desktop\ludum_dare\ludumdare33\Code\ClientGame\LD33.obj ClientGame

And it pretty much states similar for every single function in Monster.

Sorry for just dumping a ton of code. I've been trying to debug it for awhile but couldn't come up with any reasonable solution. I have the include guards, I don't see any namespace conflicts, and everything that needs to be defined is outside of the header files. I can't find anything in augments.h that would be causing this. I also thought it might be the enums, but replacing them with just int did not work either.

I'm thinking it might be the order of the include files? hmm. Maybe there's somehow multiple source files somewhere but I would have no clue as to how. Any help?

最满意答案

在事故发生的另一个头文件中包含了Monster.cpp! 哎呀

Had included Monster.cpp in another header file on accident! Oops

更多推荐

本文发布于:2023-08-04 15:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1417845.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   乘法   符号   定义   错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!