Multiple Definitions Error

I have decided to make my own game engine using SFML (2.0) however i can't get far because i am getting several Multiple Definitions Errors. I have checked and i can't find any more definitions of the functions so could you please help.

main.cpp
1
2
3
4
5
6
7
8
9
#include "Media/Code/Game.cpp"

int main()
{
    Game game;
    game.run();
    
    return 0;
}


Game.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#ifndef GAME_H
#define GAME_H

#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>

class Game
{
public:
    Game();

    void run();

    void handleInput();
	void update(sf::Time delta);
	void render();

	static const int width = 800;
	static const int height = 600;

private:
    sf::RenderWindow window;
    sf::Music bgMusic;
};

#endif // GAME_H 


Game.cpp
1
2
3
4
5
6
7
8
9
10
11
12
#include "Game.h"

Game::Game()
: window(sf::VideoMode(Game::width, Game::height), "<game name>")
{
}

void Game::run()
{
    sf::Clock clock;
	sf::Time timeSinceLastUpdate = sf::Time::Zero;
}


and here are the errors i get

obj\Debug\Media\Code\Game.o||In function `ZN4GameC2Ev':|
Game Engine\Media\Code\Game.cpp|3|multiple definition of `Game::Game()'|
obj\Debug\main.o:Game Engine\Media\Code\Game.cpp|3|first defined here|
obj\Debug\Media\Code\Game.o||In function `ZN4GameC2Ev':|
Game Engine\Media\Code\Game.cpp|3|multiple definition of `Game::Game()'|
obj\Debug\main.o:Game Engine\Media\Code\Game.cpp|3|first defined here|
obj\Debug\Media\Code\Game.o||In function `ZN4Game3runEv':|
Game Engine\Media\Code\Game.cpp|9|multiple definition of `Game::run()'|
obj\Debug\main.o:Game Engine\Media\Code\Game.cpp|9|first defined here|
obj\Debug\main.o:main.cpp|| undefined reference to `sf::Music::Music()'|
obj\Debug\main.o:main.cpp:(.text$_ZN4GameD1Ev[__ZN4GameD1Ev]+0x4a)||undefined reference to `sf::Music::~Music()'|
obj\Debug\Media\Code\Game.o:Game.cpp|| undefined reference to `sf::Music::Music()'|
Last edited on
yep sorry i misread where i was learning from

i have fixed it now
Topic archived. No new replies allowed.