1>Main.obj : error LNK2005: "void __cdecl initializeGame(void)" (?initializeGame@@YAXXZ) already defined in Blocks.obj
1>Main.obj : error LNK2005: "void __cdecl endGame(void)" (?endGame@@YAXXZ) already defined in Blocks.obj
1>Debug\TETRIS RAMPAGE.exe : fatal error LNK1169: one or more multiply defined symbols found
I received the above error after running my program on DarkGDK. I created a .cpp file called blocks.cpp and wrote a few functions for a class that I created in the header file, blocks.h, and then when I test it in the main function, it comes up with this error, which references my two functions endGame() and initializeGame() that had worked previously. Can anyone shed any insight as to where this problem came from and how I can fix it?
It's not finished yet, and you might find that some of the numbers are wrong, because I was unable to test it with these errors, so I apologize.
Here's the relevant code:
In Main.cpp:
void DarkGDK ( void )
{
//Load Files, create sprites and initiate game
initializeGame();
bool game = true;
block b1;
b1.createBlock(10, CYAN);
//Show user menu
//Begin Gameplay
while(LoopGDK())
{
if(dbEscapeKey())
{
game = false;
}
if(dbLeftKey())
{
b1.move(LEFT, 30);
}
if(dbRightKey())
{
b1.move(RIGHT, 30);
}
if(dbUpKey())
{
b1.move(UP, 30);
}
if(dbDownKey())
{
b1.move(DOWN, 30);
}
if(dbKeyState(DIK_P) == 1)
{
dbHideSprite(1);
dbWaitKey();
}
if(game == false)
{
break;
}
dbSync();
}
//Delete all sprites/Deallocate Memory
endGame();
return;
}
Then I have a class in blocks.h with function prototypes. I also have a file called Tetris.h which includes all necessary files and is also included in the other header files... I created a wrapper for each header file.
In blocks.cpp:
#include "Tetris.h"
using namespace std;
void block::createBlock(int ID, int color)
{//creates block by default at (0,0), use moveTo to spawn block elsewhere
blockID = ID;
if(color == CYAN)
{
dbSprite(ID, 0, 0, 6);
}
else if(color == YELLOW)
{
dbSprite(ID, 0, 0, 4);
}
else if(color == PURPLE)
{
dbSprite(ID, 0, 0, 8);
}
else if(color == GREEN)
{
dbSprite(ID, 0, 0, 5);
}
else if(color == RED)
{
dbSprite(ID, 0, 0, 2);
}
else if(color == BLUE)
{
dbSprite(ID, 0, 0, 7);
}
else if(color == ORANGE)
{
dbSprite(ID, 0, 0, 3);
}
}
void block::destroy()
{
dbDeleteSprite(blockID);
}
void block::rotate(int angle)
{
int newAngle = dbSpriteAngle(blockID) + angle;
while(newAngle >= 360)
{
newAngle -= 360;
}
while(newAngle < 0)
{
newAngle += 360;
}
dbRotateSprite(blockID, newAngle);
}
void block::rotateTo(int angle)
{
dbRotateSprite(blockID, angle);
}
void block::move(int direction, int velocity)
{
if(direction == UP)
{
dbMoveSprite(blockID, velocity);
}
else if(direction == DOWN)
{
dbMoveSprite(blockID, -1 * velocity);
}
else if(direction == RIGHT)
{
rotateTo(90);
dbMoveSprite(blockID, velocity);
rotateTo(0);
}
else if(direction == LEFT)
{
rotateTo(90);
dbMoveSprite(blockID, -1 * velocity);
rotateTo(0);
}
}
void block::moveTo(int X, int Y)
{
move(RIGHT, dbSpriteX(blockID));
move(UP, dbSpriteY(blockID));
move(LEFT, X);
move(RIGHT, Y);
}
Thanks in advance.