0

Alright, so I'm trying to make a simple game engine using SFML in Visual Studio 2012. What's happening is, I have my header file, Game.hpp:

#ifndef _GAME_H
#define _GAME_H
#include<SFML\Graphics.hpp>
#include<iostream>

class Game
{
private:
    sf::RenderWindow Window;
    sf::Time ElapsedTime;
    sf::Time PreviousTime;
    float DeltaTime;
    sf::Clock clock;
    bool Running;
    sf::Event polledEvent;
    sf::RectangleShape rectshape;
    sf::Font arialFont;
    sf::Text testtext;
public:
    Game();
    int OnExecute();

public:
    void Init();
    void Update();
    void Draw();
    void Event(sf::Event polledEvent);
    void Cleanup();
};
#endif

and my Game.cpp file for the constructor:

#include "Game.hpp"
Game::Game()
{
Window.create(sf::VideoMode(800,600),"Name Me!");
Window.setFramerateLimit(30);
Running = true;
}

Any changes in the slightest to Game.hpp break compilation, with the linker error:

error LNK2019: unresolved external symbol "public: __thiscall Game::Game(void)" (??0Game@@QAE@XZ) referenced in function _main  Program.obj SFML-Project

and the warning:

warning LNK4042: object specified more than once; extras ignored    

After forcing it to alternately attempt to rebuild Game.hpp, then Game.cpp(by changing something minor, like adding and deleting a space), it compiles fine. Every single other function is in its own cpp file, and not caring. If Game.hpp doesn't need to be updated, the linker doesn't flag any errors. It is only these two that are fighting.

What causes this error and how to I fix it?

EDIT: I threw all of my implementation code into Game.cpp just to see if that'd do anything. Still the same issue. If I, for example, add a variable to my Game.hpp file, then reference it in a function in my Game.cpp file, it'll go through, build my main file, Game.cpp, and Game.hpp. It'll flag the error. I'll then go through, add a space and backspace, enough to flag the file as "changed," and hit build. It builds without errors.

Andrew Q
  • 9
  • 5
  • Seems like you misunderstand the compilation process. Headers are generally not compiled by themselves - they are included into implementation files which are then compiled. – Joseph Mansfield Dec 24 '13 at 20:38
  • What would be the correct terminology in this instance then? Because changes in the hpp file break the cpp file, but if I do a minor change in the cpp file, everything is happy again. – Andrew Q Dec 24 '13 at 20:42
  • If you change the hpp file the. you must recompile all dependent cpp files. Othérwise you have a mismatch that leads to all sorts of problems. – Raymond Chen Dec 24 '13 at 21:36
  • I'm not sure that's the issue, because if I rebuild the project, it still breaks. – Andrew Q Dec 24 '13 at 23:20

1 Answers1

0

As far as I can tell, my project is just broken beyond measure. My best guess is that I accidentally created "Game.hpp" as a cpp file, and then switched it to a header file, but it was still flagged for compilation, hence why it was continuously being compiled. I created a new project, and copy-pasted the code over, and everything seems to be working fine now. I tried a few little things here and there, but I can't seem to figure out what I did to the project. My issue is fixed, although I'd love to figure out why it happened in the first place.

Andrew Q
  • 9
  • 5