找到一个或多个多次定义的符号,错误 LNK1169 C++

One or more multiply defined symbols found, error LNK1169 C++

抱歉缺少描述性标题。 我收到一个错误 "one or more multiply defined symbols found";更具体地说,我得到了其中的 46 个。我的 header/source 文件中的每个函数一个。使用 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 中的每个功能都非常相似。

很抱歉刚刚转储了大量代码。我一直在尝试调试它一段时间,但无法想出任何合理的解决方案。我有 include 守卫,我没有看到任何名称空间冲突,并且需要定义的所有内容都在 header 文件之外。我在 augments.h 中找不到任何导致此问题的内容。我也认为它可能是枚举,但用 int 替换它们也不起作用。

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

不小心在另一个头文件中包含了 Monster.cpp!糟糕