LNK2005 Errors galore
I just don't get it, I have several files in a program I'm meant to be writing, at the moment two header files and two C++ files to go with them.
The first header file defines some variables using #define and the structure of a class called GameState.
The first header file defines some variables using #define and the structure of a class called GameState.
#pragma once
#include [Error: Irreparable invalid markup ('<windows.h>') in entry. Owner must fix manually. Raw contents below.]
I just don't get it, I have several files in a program I'm meant to be writing, at the moment two header files and two C++ files to go with them.
The first header file defines some variables using #define and the structure of a class called GameState.<center><lj-cut text="gamestate.h code"></center><code>#pragma once
#include <windows.h>
#define STATE_START 0x0000
#define STATE_TITLE 0x0001
#define STATE_BEGIN 0x0002
#define STATE_PLAY 0x0003
#define STATE_DEAD 0x0004
#define STATE_OVER 0x0005
#define STATE_DONE 0x0006
#define EASY 0x0001
#define NORMAL 0x0002
#define HARD 0x0004
#define NIGHTMARE 0x0008
/*
* This object holds various pieces of information about the game
* including timing data,
* the current level,
* the current difficulty,
* a pointer to the appropriate draw function
* the current state of the game
*
*/
class GameState
{
DWORD m_oldtime;
DWORD m_newtime;
DWORD m_interval;
int m_level;
int m_difficulty;
UINT m_state;
public:
GameState();
bool EnoughTimePassed();
inline void IncreaseLevel();
inline int GetLevel();
bool SetDifficulty(int);
inline int GetDifficulty();
bool SetState(UINT);
inline UINT GetState();
};</code></lj-cut></center>
The C++ file that accompanies it then provides the actual code to go with the functions. I then have another header file which draws things depending on the state of the game, called draw.h.<center><lj-cut text="Draw header"></center><code>#pragma once
#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>
#include "gl_window.cpp"
#include "sys_gamestate.cpp"
//#include "game_titlescreen.cpp"
//#include "game_creditscreen.cpp"
//#include "game_overscreen.cpp"
//#include "game_entitylist.cpp"
#ifdef WIN32
#pragma comment( lib, "Opengl32.lib" )
#pragma comment( lib, "glaux.lib" )
#pragma comment( lib, "glu32.lib" )
#endif
#ifdef WIN16
#pragma comment( lib, "Opengl.lib" )
#pragma comment( lib, "glaux.lib" )
#pragma comment( lib, "glu.lib" )
#endif
/*
* This file will do all the drawing and have lots of different functions to do the drawing with...
*/
void (*currentdrawer)();
GLvoid GL_TitleScene();
GLvoid GL_MainScene();
GLvoid GL_OverScene();
GLvoid GL_CreditScene();
GLvoid GL_Draw();</code></lj-cut></center>
The C++ file accompanying it again specifiying exactly what each function needs to do. My intention is to have other files call the GL_Draw() function of draw.cpp, that function will then check the state of the game via a call to GetState() from an instance of the GameState class and assign the correct drawing function (one of the *Scenes) to the function pointer which then draws to the screen.
But every time I even so much as mention in the draw.cpp file anything to do with the GameState object I get a whole list of LNK2005 errors. <center><lj-cut text="Linker errors"></center><code>Pharax error LNK2005: "void __cdecl GL_KillWindow(void)" (?GL_KillWindow@@YAXXZ) already defined in gl_draw.obj
Pharax error LNK2005: "bool __cdecl GL_Init(void)" (?GL_Init@@YA_NXZ) already defined in gl_draw.obj
Pharax error LNK2005: "bool __cdecl GL_CreateWindow(char *,int,int,int,bool)" (?GL_CreateWindow@@YA_NPADHHH_N@Z) already defined in gl_draw.obj
Pharax error LNK2005: "void __cdecl GL_ResizeScene(int,int)" (?GL_ResizeScene@@YAXHH@Z) already defined in gl_draw.obj
Pharax error LNK2005: "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) already defined in gl_draw.obj
Pharax error LNK2005: "char * title" (?title@@3PADA) already defined in gl_draw.obj
Pharax error LNK2005: "int infoheight" (?infoheight@@3HA) already defined in gl_draw.obj
Pharax error LNK2005: "int sheight" (?sheight@@3HA) already defined in gl_draw.obj
Pharax error LNK2005: "int swidth" (?swidth@@3HA) already defined in gl_draw.obj
Pharax error LNK2005: "bool paused" (?paused@@3_NA) already defined in gl_draw.obj
Pharax error LNK2005: "bool active" (?active@@3_NA) already defined in gl_draw.obj
Pharax error LNK2005: "bool fullscreen" (?fullscreen@@3_NA) already defined in gl_draw.obj
Pharax error LNK2005: "struct HINSTANCE__ * hInstance" (?hInstance@@3PAUHINSTANCE__@@A) already defined in gl_draw.obj
Pharax error LNK2005: "struct HWND__ * hWnd" (?hWnd@@3PAUHWND__@@A) already defined in gl_draw.obj
Pharax error LNK2005: "struct HDC__ * hDC" (?hDC@@3PAUHDC__@@A) already defined in gl_draw.obj
Pharax error LNK2005: "struct HGLRC__ * hRC" (?hRC@@3PAUHGLRC__@@A) already defined in gl_draw.obj
Pharax error LNK2005: "public: __thiscall GameState::GameState(void)" (??0GameState@@QAE@XZ) already defined in gl_draw.obj
Pharax error LNK2005: "public: bool __thiscall GameState::EnoughTimePassed(void)" (?EnoughTimePassed@GameState@@QAE_NXZ) already defined in gl_draw.obj
Pharax error LNK2005: "public: bool __thiscall GameState::SetDifficulty(int)" (?SetDifficulty@GameState@@QAE_NH@Z) already defined in gl_draw.obj
Pharax error LNK2005: "public: bool __thiscall GameState::SetState(unsigned int)" (?SetState@GameState@@QAE_NI@Z) already defined in gl_draw.obj
Pharax error LNK2005: "bool __cdecl GL_Init(void)" (?GL_Init@@YA_NXZ) already defined in gl_draw.obj
Pharax error LNK2005: "void __cdecl GL_KillWindow(void)" (?GL_KillWindow@@YAXXZ) already defined in gl_draw.obj
Pharax error LNK2005: "bool __cdecl GL_CreateWindow(char *,int,int,int,bool)" (?GL_CreateWindow@@YA_NPADHHH_N@Z) already defined in gl_draw.obj
Pharax error LNK2005: "void __cdecl GL_ResizeScene(int,int)" (?GL_ResizeScene@@YAXHH@Z) already defined in gl_draw.obj
Pharax error LNK2005: "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) already defined in gl_draw.obj
Pharax error LNK2005: "public: __thiscall GameState::GameState(void)" (??0GameState@@QAE@XZ) already defined in gl_draw.obj
Pharax error LNK2005: "public: bool __thiscall GameState::EnoughTimePassed(void)" (?EnoughTimePassed@GameState@@QAE_NXZ) already defined in gl_draw.obj
Pharax error LNK2005: "public: bool __thiscall GameState::SetDifficulty(int)" (?SetDifficulty@GameState@@QAE_NH@Z) already defined in gl_draw.obj
Pharax error LNK2005: "public: bool __thiscall GameState::SetState(unsigned int)" (?SetState@GameState@@QAE_NI@Z) already defined in gl_draw.obj
Pharax error LNK2005: "void __cdecl GL_TitleScene(void)" (?GL_TitleScene@@YAXXZ) already defined in gl_draw.obj
Pharax error LNK2005: "void __cdecl GL_MainScene(void)" (?GL_MainScene@@YAXXZ) already defined in gl_draw.obj
Pharax error LNK2005: "void __cdecl GL_OverScene(void)" (?GL_OverScene@@YAXXZ) already defined in gl_draw.obj
Pharax error LNK2005: "void __cdecl GL_CreditScene(void)" (?GL_CreditScene@@YAXXZ) already defined in gl_draw.obj
Pharax error LNK2005: "void __cdecl GL_Draw(void)" (?GL_Draw@@YAXXZ) already defined in gl_draw.obj
Pharax error LNK2005: "char * title" (?title@@3PADA) already defined in gl_draw.obj
Pharax error LNK2005: "int infoheight" (?infoheight@@3HA) already defined in gl_draw.obj
Pharax error LNK2005: "int sheight" (?sheight@@3HA) already defined in gl_draw.obj
Pharax error LNK2005: "int swidth" (?swidth@@3HA) already defined in gl_draw.obj
Pharax error LNK2005: "bool paused" (?paused@@3_NA) already defined in gl_draw.obj
Pharax error LNK2005: "bool active" (?active@@3_NA) already defined in gl_draw.obj
Pharax error LNK2005: "bool fullscreen" (?fullscreen@@3_NA) already defined in gl_draw.obj
Pharax error LNK2005: "struct HINSTANCE__ * hInstance" (?hInstance@@3PAUHINSTANCE__@@A) already defined in gl_draw.obj
Pharax error LNK2005: "struct HWND__ * hWnd" (?hWnd@@3PAUHWND__@@A) already defined in gl_draw.obj
Pharax error LNK2005: "struct HDC__ * hDC" (?hDC@@3PAUHDC__@@A) already defined in gl_draw.obj
Pharax error LNK2005: "struct HGLRC__ * hRC" (?hRC@@3PAUHGLRC__@@A) already defined in gl_draw.obj
Pharax error LNK2005: "void (__cdecl* currentdrawer)(void)" (?currentdrawer@@3P6AXXZA) already defined in gl_draw.obj
Pharax fatal error LNK1169: one or more multiply defined symbols found
</code></lj-cut></center>
Does anyone have any idea what the hell is going on with this and what I can do to fix it, it's driving me mad :s
The first header file defines some variables using #define and the structure of a class called GameState.<center><lj-cut text="gamestate.h code"></center><code>#pragma once
#include <windows.h>
#define STATE_START 0x0000
#define STATE_TITLE 0x0001
#define STATE_BEGIN 0x0002
#define STATE_PLAY 0x0003
#define STATE_DEAD 0x0004
#define STATE_OVER 0x0005
#define STATE_DONE 0x0006
#define EASY 0x0001
#define NORMAL 0x0002
#define HARD 0x0004
#define NIGHTMARE 0x0008
/*
* This object holds various pieces of information about the game
* including timing data,
* the current level,
* the current difficulty,
* a pointer to the appropriate draw function
* the current state of the game
*
*/
class GameState
{
DWORD m_oldtime;
DWORD m_newtime;
DWORD m_interval;
int m_level;
int m_difficulty;
UINT m_state;
public:
GameState();
bool EnoughTimePassed();
inline void IncreaseLevel();
inline int GetLevel();
bool SetDifficulty(int);
inline int GetDifficulty();
bool SetState(UINT);
inline UINT GetState();
};</code></lj-cut></center>
The C++ file that accompanies it then provides the actual code to go with the functions. I then have another header file which draws things depending on the state of the game, called draw.h.<center><lj-cut text="Draw header"></center><code>#pragma once
#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>
#include "gl_window.cpp"
#include "sys_gamestate.cpp"
//#include "game_titlescreen.cpp"
//#include "game_creditscreen.cpp"
//#include "game_overscreen.cpp"
//#include "game_entitylist.cpp"
#ifdef WIN32
#pragma comment( lib, "Opengl32.lib" )
#pragma comment( lib, "glaux.lib" )
#pragma comment( lib, "glu32.lib" )
#endif
#ifdef WIN16
#pragma comment( lib, "Opengl.lib" )
#pragma comment( lib, "glaux.lib" )
#pragma comment( lib, "glu.lib" )
#endif
/*
* This file will do all the drawing and have lots of different functions to do the drawing with...
*/
void (*currentdrawer)();
GLvoid GL_TitleScene();
GLvoid GL_MainScene();
GLvoid GL_OverScene();
GLvoid GL_CreditScene();
GLvoid GL_Draw();</code></lj-cut></center>
The C++ file accompanying it again specifiying exactly what each function needs to do. My intention is to have other files call the GL_Draw() function of draw.cpp, that function will then check the state of the game via a call to GetState() from an instance of the GameState class and assign the correct drawing function (one of the *Scenes) to the function pointer which then draws to the screen.
But every time I even so much as mention in the draw.cpp file anything to do with the GameState object I get a whole list of LNK2005 errors. <center><lj-cut text="Linker errors"></center><code>Pharax error LNK2005: "void __cdecl GL_KillWindow(void)" (?GL_KillWindow@@YAXXZ) already defined in gl_draw.obj
Pharax error LNK2005: "bool __cdecl GL_Init(void)" (?GL_Init@@YA_NXZ) already defined in gl_draw.obj
Pharax error LNK2005: "bool __cdecl GL_CreateWindow(char *,int,int,int,bool)" (?GL_CreateWindow@@YA_NPADHHH_N@Z) already defined in gl_draw.obj
Pharax error LNK2005: "void __cdecl GL_ResizeScene(int,int)" (?GL_ResizeScene@@YAXHH@Z) already defined in gl_draw.obj
Pharax error LNK2005: "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) already defined in gl_draw.obj
Pharax error LNK2005: "char * title" (?title@@3PADA) already defined in gl_draw.obj
Pharax error LNK2005: "int infoheight" (?infoheight@@3HA) already defined in gl_draw.obj
Pharax error LNK2005: "int sheight" (?sheight@@3HA) already defined in gl_draw.obj
Pharax error LNK2005: "int swidth" (?swidth@@3HA) already defined in gl_draw.obj
Pharax error LNK2005: "bool paused" (?paused@@3_NA) already defined in gl_draw.obj
Pharax error LNK2005: "bool active" (?active@@3_NA) already defined in gl_draw.obj
Pharax error LNK2005: "bool fullscreen" (?fullscreen@@3_NA) already defined in gl_draw.obj
Pharax error LNK2005: "struct HINSTANCE__ * hInstance" (?hInstance@@3PAUHINSTANCE__@@A) already defined in gl_draw.obj
Pharax error LNK2005: "struct HWND__ * hWnd" (?hWnd@@3PAUHWND__@@A) already defined in gl_draw.obj
Pharax error LNK2005: "struct HDC__ * hDC" (?hDC@@3PAUHDC__@@A) already defined in gl_draw.obj
Pharax error LNK2005: "struct HGLRC__ * hRC" (?hRC@@3PAUHGLRC__@@A) already defined in gl_draw.obj
Pharax error LNK2005: "public: __thiscall GameState::GameState(void)" (??0GameState@@QAE@XZ) already defined in gl_draw.obj
Pharax error LNK2005: "public: bool __thiscall GameState::EnoughTimePassed(void)" (?EnoughTimePassed@GameState@@QAE_NXZ) already defined in gl_draw.obj
Pharax error LNK2005: "public: bool __thiscall GameState::SetDifficulty(int)" (?SetDifficulty@GameState@@QAE_NH@Z) already defined in gl_draw.obj
Pharax error LNK2005: "public: bool __thiscall GameState::SetState(unsigned int)" (?SetState@GameState@@QAE_NI@Z) already defined in gl_draw.obj
Pharax error LNK2005: "bool __cdecl GL_Init(void)" (?GL_Init@@YA_NXZ) already defined in gl_draw.obj
Pharax error LNK2005: "void __cdecl GL_KillWindow(void)" (?GL_KillWindow@@YAXXZ) already defined in gl_draw.obj
Pharax error LNK2005: "bool __cdecl GL_CreateWindow(char *,int,int,int,bool)" (?GL_CreateWindow@@YA_NPADHHH_N@Z) already defined in gl_draw.obj
Pharax error LNK2005: "void __cdecl GL_ResizeScene(int,int)" (?GL_ResizeScene@@YAXHH@Z) already defined in gl_draw.obj
Pharax error LNK2005: "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) already defined in gl_draw.obj
Pharax error LNK2005: "public: __thiscall GameState::GameState(void)" (??0GameState@@QAE@XZ) already defined in gl_draw.obj
Pharax error LNK2005: "public: bool __thiscall GameState::EnoughTimePassed(void)" (?EnoughTimePassed@GameState@@QAE_NXZ) already defined in gl_draw.obj
Pharax error LNK2005: "public: bool __thiscall GameState::SetDifficulty(int)" (?SetDifficulty@GameState@@QAE_NH@Z) already defined in gl_draw.obj
Pharax error LNK2005: "public: bool __thiscall GameState::SetState(unsigned int)" (?SetState@GameState@@QAE_NI@Z) already defined in gl_draw.obj
Pharax error LNK2005: "void __cdecl GL_TitleScene(void)" (?GL_TitleScene@@YAXXZ) already defined in gl_draw.obj
Pharax error LNK2005: "void __cdecl GL_MainScene(void)" (?GL_MainScene@@YAXXZ) already defined in gl_draw.obj
Pharax error LNK2005: "void __cdecl GL_OverScene(void)" (?GL_OverScene@@YAXXZ) already defined in gl_draw.obj
Pharax error LNK2005: "void __cdecl GL_CreditScene(void)" (?GL_CreditScene@@YAXXZ) already defined in gl_draw.obj
Pharax error LNK2005: "void __cdecl GL_Draw(void)" (?GL_Draw@@YAXXZ) already defined in gl_draw.obj
Pharax error LNK2005: "char * title" (?title@@3PADA) already defined in gl_draw.obj
Pharax error LNK2005: "int infoheight" (?infoheight@@3HA) already defined in gl_draw.obj
Pharax error LNK2005: "int sheight" (?sheight@@3HA) already defined in gl_draw.obj
Pharax error LNK2005: "int swidth" (?swidth@@3HA) already defined in gl_draw.obj
Pharax error LNK2005: "bool paused" (?paused@@3_NA) already defined in gl_draw.obj
Pharax error LNK2005: "bool active" (?active@@3_NA) already defined in gl_draw.obj
Pharax error LNK2005: "bool fullscreen" (?fullscreen@@3_NA) already defined in gl_draw.obj
Pharax error LNK2005: "struct HINSTANCE__ * hInstance" (?hInstance@@3PAUHINSTANCE__@@A) already defined in gl_draw.obj
Pharax error LNK2005: "struct HWND__ * hWnd" (?hWnd@@3PAUHWND__@@A) already defined in gl_draw.obj
Pharax error LNK2005: "struct HDC__ * hDC" (?hDC@@3PAUHDC__@@A) already defined in gl_draw.obj
Pharax error LNK2005: "struct HGLRC__ * hRC" (?hRC@@3PAUHGLRC__@@A) already defined in gl_draw.obj
Pharax error LNK2005: "void (__cdecl* currentdrawer)(void)" (?currentdrawer@@3P6AXXZA) already defined in gl_draw.obj
Pharax fatal error LNK1169: one or more multiply defined symbols found
</code></lj-cut></center>
Does anyone have any idea what the hell is going on with this and what I can do to fix it, it's driving me mad :s
