CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    May 2010
    Posts
    7

    Angry "fatal error LNK1169: one or more multiply defined symbols found"

    Hello all,

    I've been dealing with this error for a bit, and as much as I attempt to error trap the bugger, I can't find where it's being caused from. There is a good chance that I'm missing a very simple answer, but even if it is - it's driving me nuts.

    The error I am referring to is the dreaded:
    fatal error LNK1169: one or more multiply defined symbols found
    .
    I'm aware of what this error GENERALLY means, but I can not for the life of me understand why I am still getting it.

    The full error is:
    error LNK2005: "class COORDINATES * Game_Player::coordinates" (?coordinates@Game_Player@@$$Q3PAVCOORDINATES@@A) already defined in Roleplaying game.obj
    G:\Program\Roleplaying game\Debug\Roleplaying game.exe : fatal error LNK1169: one or more multiply defined symbols found
    Because of the size of my project, I won't be able to show the entire thing of code, but I will isolate where the errors are all coming from.
    The definition of class COORDINATES, as stated in the error above, comes from this (this is just the definition, because the whole thing normally has many more declarations)

    Code:
    //┌───────────────────────────────────────────────────────────────────────────────────────────────────────────
    //│ ** Game_System
    //├───────────────────────────────────────────────────────────────────────────────────────────────────────────
    //│ This header handles data surrounding the system. Enumerations, typedefs, background music, 
    //│ windowskins, etc. are managed here as well.
    //└───────────────────────────────────────────────────────────────────────────────────────────────────────────
    #ifndef GAME_SYSTEM_H
    #define	GAME_SYSTEM_H
    #pragma once
    
    //┌───────────────────────────────────────────────────────────────────────────────────────────────────────────
    //│ * POSITION (coordinate) class
    //└───────────────────────────────────────────────────────────────────────────────────────────────────────────
    typedef class COORDINATES
    {
    public:
    	short		x_pos,		y_pos;
    	//Constructors
    	explicit COORDINATES		( );
    	COORDINATES				( short x, short y );
    	//Operations
    	COORDINATES operator+		( COORDINATES TEMP );
    	COORDINATES operator+		( uint16	  TEMP );
    	COORDINATES operator-		( COORDINATES TEMP );
    	COORDINATES operator-		( uint16	  TEMP );
    	COORDINATES operator*		( COORDINATES TEMP );
    	COORDINATES operator*		( uint16	  TEMP );
    	COORDINATES operator/		( COORDINATES TEMP );
    	COORDINATES operator/		( uint16 	  TEMP );
    	COORDINATES operator%	( COORDINATES TEMP );
    	COORDINATES operator%	( uint16	  TEMP );
    	COORDINATES operator+=	( COORDINATES TEMP );
    	COORDINATES operator-=	( COORDINATES TEMP );
    	COORDINATES operator*=	( COORDINATES TEMP );
    	COORDINATES operator/=	( COORDINATES TEMP );
    	COORDINATES operator%=	( COORDINATES TEMP );
    	bool		operator==		( COORDINATES TEMP );
    	bool		operator!=		( COORDINATES TEMP );
    } *POSITION, NEWCOORD;
    #endif
    and the corresponding .cpp file
    Code:
    #include "stdafx.h"
    #include "Game_System.h"
    //┌───────────────────────────────────────────────────────────────────────────────────────────────────────────
    //│ * POSITION (coordinate) class
    //└───────────────────────────────────────────────────────────────────────────────────────────────────────────
    COORDINATES::COORDINATES			( )					{x_pos = y_pos = NIL;			}
    COORDINATES::COORDINATES			( short x, short y )		{x_pos = x;			y_pos = y;	}
    COORDINATES COORDINATES::operator+	( COORDINATES TEMP )	{return COORDINATES(x_pos + TEMP.x_pos,		y_pos + TEMP.y_pos);		}
    COORDINATES COORDINATES::operator+	( uint16	  TEMP )		{return COORDINATES(x_pos + TEMP,			y_pos + TEMP);				}
    COORDINATES COORDINATES::operator-	( COORDINATES TEMP )	{return COORDINATES(x_pos - TEMP.x_pos,		y_pos - TEMP.y_pos);		}
    COORDINATES COORDINATES::operator-	( uint16	  TEMP )		{return COORDINATES(x_pos - TEMP,			y_pos - TEMP);				}
    COORDINATES COORDINATES::operator*	( COORDINATES TEMP )	{return COORDINATES(x_pos * TEMP.x_pos,		y_pos * TEMP.y_pos);		}
    COORDINATES COORDINATES::operator*	( uint16	  TEMP )		{return COORDINATES(x_pos * TEMP,			y_pos * TEMP);				}
    COORDINATES COORDINATES::operator/	( COORDINATES TEMP )	{return COORDINATES(x_pos / TEMP.x_pos,		y_pos / TEMP.y_pos);		}
    COORDINATES COORDINATES::operator/	( uint16	  TEMP )		{return COORDINATES(x_pos / TEMP,			y_pos / TEMP);				}
    COORDINATES COORDINATES::operator%	( COORDINATES TEMP )	{return COORDINATES(x_pos % TEMP.x_pos,		y_pos % TEMP.y_pos);		}
    COORDINATES COORDINATES::operator%	( uint16	  TEMP )		{return COORDINATES(x_pos % TEMP,			y_pos % TEMP);				}
    COORDINATES COORDINATES::operator+=	( COORDINATES TEMP )	{return COORDINATES(x_pos + TEMP.x_pos,		y_pos + TEMP.y_pos);		}
    COORDINATES COORDINATES::operator-=	( COORDINATES TEMP )	{return COORDINATES(x_pos - TEMP.x_pos,		y_pos - TEMP.y_pos);		}
    COORDINATES COORDINATES::operator*=	( COORDINATES TEMP )	{return COORDINATES(x_pos * TEMP.x_pos,		y_pos * TEMP.y_pos);		}
    COORDINATES COORDINATES::operator/=	( COORDINATES TEMP )	{return COORDINATES(x_pos / TEMP.x_pos,		y_pos * TEMP.y_pos);		}
    COORDINATES COORDINATES::operator%=	( COORDINATES TEMP )	{return COORDINATES(x_pos % TEMP.x_pos,		y_pos % TEMP.y_pos);		}
    bool		COORDINATES::operator==		( COORDINATES TEMP )	{return (x_pos==TEMP.x_pos ? (y_pos==TEMP.y_pos ? true : false): false);}
    bool		COORDINATES::operator!=		( COORDINATES TEMP )	{return (x_pos!=TEMP.x_pos ? true : (y_pos!=TEMP.y_pos ? true : false));}

    That's the declaration/definition of the class.
    The part where I'm getting the error with the code is in Game_Actor.h

    Code:
    //┌───────────────────────────────────────────────────────────────────────────────────────────────────────────
    //│ ** Game_Player
    //├───────────────────────────────────────────────────────────────────────────────────────────────────────────
    //│ This header handles data surrounding the game data. This include event passing, co-ordinate tracking, 
    //│ and collision detection.
    //└───────────────────────────────────────────────────────────────────────────────────────────────────────────
    #ifndef GAME_PLAYER_H
    #define	GAME_PLAYER_H
    #pragma once
    
    //┌───────────────────────────────────────────────────────────────────────────────────────────────────────────
    //│ * Public Instance Variables
    //└───────────────────────────────────────────────────────────────────────────────────────────────────────────
    namespace Game_Player
    {
    	POSITION	coordinates;
    	
    	bool		passable		(POSITION position) throw();			//
    	bool		check_event	(POSITION position) throw();			//
    	void		center		(POSITION position) throw();			//
    	void		moveto		(POSITION position, short direction);	//
    };
    
    #endif
    and the corresponding .cpp file contains the three headers (I'm sparing the definitions of the functions):
    Code:
    #include "stdafx.h"
    #include "Game_System.h"
    #include "Game_Player.h"
    Normally I don't use both #pragma once and #ifndef; I normally just use the #ifndef for my safegaurding, but because of the annoying error that I keep receiving, I have tried adding both - to which I continue to receive the error.

    At the present moment in time, these are the only 2 files in my project (save for the file for the form, which contains no declaration of "POSITION", "COORDINATES", etc..
    In an attempt to check for this error, I have already commented out nearly all pre-existing code, I have already tried renaming the variable above to make sure it's not a naming error, to which the likes of "MY_REALLY_RANDOMLY_NAMED_VARIABLE" still contains the error.
    I have also tried changing the namespace to a class, and - for some bizarre reason - doing so temporarily completely removed the error. If this were an unnamed namespace, I could understand the error, but the fact that i have given it a name is what confuses me.

    The only thing I can think of is that it's the included order of the header files (because the main form also contains include for the two of them to make them part of the system). I know that the stdafx file is for including other headers, but I'm not sure if that is exactly where I'm supposed to go because, prior to this project, my work always remained in pure console where I designed all the code and didn't use pre-made code.


    It's likely an error so simple that I have overlooked it, but it's been driving me up the wall for some time (normally I just comment it out and it will run fine without it because it's not used, at the moment)

    If someone could help me and has endured the long grueling explanation, I would really appreciate the aide.

    Thanks in advance to all who offer their help :P

    ~TheDiabolicalPupeteer

    Edit 1:
    Sorry if the code shows up messed up. The tabbing on this forum is different from in my compiler, which my code is really neat.
    Another note: I think spoilers would be useful in this forum for adding code inside.

    Edit 2:
    I forgot to mention that this error occurs with any of my defined classes or templates, but it appears to only happen in this header (perhaps because of the namespace issue mentioned above?)
    I also forgot to mention that I am using Microsoft Visual Studio 2008 (though I doubt it is compiler error, it's likely an oversight on my part).

    Another thing I'd like to note is that if the required files are to be included into the stdafx file, that I don't know which ones to include into them - and so if someone could offer some insight into that at the same time, I'd appreciate it.
    Last edited by TheDiabolicalPupeteer; June 7th, 2010 at 09:16 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured