One or more multiply defined symbols found.

I came back to a project of mine after some time and I quickly remembered why I stopped working on it. I cannot solve this error:

Error LNK1169 one or more multiply defined symbols found

I think I understand what its angry about, but the only way I can solve this issue is to comment out my function definitions in my game.cpp file. I am a little confused on what to do about this error. I think maybe I created the class wrong, but I honestly have no Idea.

EDIT: Changing the code in my main file to include "game.hpp" instead of cpp seems to have fixed the issue. Im going to leave a little time to get some feedback from others, but I will mark the issue as solved later today.

game.cpp
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "stdafx.h"
#include "Game.hpp"
#include "SplashState.hpp"

namespace TotalControl
{
	Game::Game(int width, int height, std::string title)
	{
		Data->window.create(sf::VideoMode(width, height), title, sf::Style::Close | sf::Style::Titlebar);
		Data->stateHand.AddState(StateRef(new SplashState(this->Data)));
		this->Run();
	}

	void Game::Run()
	{
		//This next bit of code is some important game engine logic. It makes it so frame times are ALWAYS the same. So the game will NOT run
		//faster on my computer over yours. It basically will make the game always feel the same. Very important.
		float newTime, frameTime, interpolation;

		float currentTime = this->Clock.getElapsedTime().asSeconds();

		float accumulator = 0.0f;

		//Enter the GAME LOOOOOOOOOOOP
		while (this->Data->window.isOpen())
		{
			//Process the state changes that have occured FIRST
			this->Data->stateHand.ProcessStateChange();

			newTime = this->Clock.getElapsedTime().asSeconds();

			frameTime = newTime - currentTime;
			if (frameTime > 0.2f)
			{
				frameTime = 0.2f;
			}
			currentTime = newTime;
			accumulator += frameTime;

			while (accumulator >= dt)
			{

				this->Data->stateHand.GetActiveState()->HandleInput();
				this->Data->stateHand.GetActiveState()->Update(dt);

				accumulator -= dt;
			}

			interpolation = accumulator / dt;
			this->Data->stateHand.GetActiveState()->Draw(interpolation);
		}
	}

	Game::~Game()
	{
	}
}


game.hpp
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#pragma once
#include <memory>
#include <string>
#include <SFML\Graphics.hpp>
#include "StateHandler.hpp"
#include "AssetsManager.hpp"
#include "InputHandler.hpp"

namespace TotalControl
{
	struct GameData
	{
		StateHandler stateHand;
		sf::RenderWindow window;
		AssetsManager assets;
		InputHandler input;
	};
	//This is a shared pointer. It basically makes a pointer to each of the things in the GameData Structure. Making it in the namespace, so its 
	//Globally accesable.
	typedef std::shared_ptr<GameData> GameDataRef;

	class Game
	{
	public:
		//Initializing our Game with everything needed for the window.
		Game(int width, int height, std::string title);

		~Game();
	private:

		//Will be called when the game starts.
		void Run();
		//This is what we will use across all states to access the managers. This makes is so it's all connected properly.
		GameDataRef Data = std::make_shared<GameData>();

		//This is for frame independent gameplay.
		const float dt = 1.0 / 60.0f;
		sf::Clock Clock;




	};
}
Last edited on
Doesn't the error message say something more about what "symbols" it has problems with?
Unfortunately no. It doesn't. I copied the error and pasted it. It also lists the file as the .exe which doesn't help much.
> EDIT: Changing the code in my main file to include "game.hpp" instead of cpp seems to have fixed the issue.
Yeah it would.
Because including .cpp files is almost always the wrong way to do it.

While you were compiling from the command line, and just compiling main.cpp, all would seem to be well.

But as soon as you move to a project based approach, where main.cpp and game.cpp are compiled separately (and then linked), you end up with multiply defined symbols.

Topic archived. No new replies allowed.