Linker Error! Help!
Posted: Sun Sep 18, 2011 3:32 am
Okay so after some busy coding I find myself with a linker error, that I just can't seem to get rid of.. I have checked throughout the files to see if I forgot to do anything, but everything seems ok, but apparently not according to Visual Studio... Visual Studio is complaining that ge::win::BaseWindow* RenderWindow has been already defined in NCMainMenu.obj, and it's complaining in the main.obj. Here's my source code, I could put up the whole project if you can help me fix it :L.
This is the source file that it is complaining about:
main.cpp
It says ge::win::BaseWindow* RenderWindow has already been defined.
NCMainMenu.h
NCMainMenu.cpp
and this is where RenderWindow is actually located at
MiguelsGameEngine.h
This is the source file that it is complaining about:
main.cpp
Code: Select all
#include <iostream>
using std::cout;
#include <vector>
// To initialize SDL
#include "InitSDLManager.h"
// For the Game-Scenes
#include "Scene.h"
// The Main Menu Scene
#include "NCMainMenu.h"
// For images
#include "SWRImage2D.h"
// For the Window
#include "MiguelsGameEngine.h"
#include "SWRWindow.h"
int main(int argc, char* argv[])
{
// Create an InitShutdownManager to automatically call SDL_Quit()
// when it goes out of scope.
ge::util::InitSDLManager SDLAutoInitalizer;
// Initialize SDL
SDLAutoInitalizer.Init(SDL_INIT_EVERYTHING);
SDLAutoInitalizer.InitSound();
SDLAutoInitalizer.InitTTF();
// Make the RenderWindow a Software rendering window.
RenderWindow = &ge::win::SWRWindow(800, 600, 32, SDL_DOUBLEBUF);
if(RenderWindow->Create() == false){
return -1;
}
ge::img::SWRImage2D icon;
if(icon.LoadImage("resources/icons/Nyan Cat.bmp") == false){
return -4;
}
SDL_WM_SetIcon(icon.getImageSurface(), 0);
std::vector<ge::util::Scene*> gameScenes;
gameScenes.push_back(&NCMainMenu());
int SceneNum = 0;
while((SceneNum = gameScenes.at(0)->MainLoop()) >= 0)
{
// Get rid of whatever is in the array..
gameScenes.pop_back();
switch(SceneNum){
case 0:
gameScenes.push_back(&NCMainMenu());
break;
default:
return SceneNum;
}
}
return SceneNum;
}
NCMainMenu.h
Code: Select all
/************************************************************************
* NCMainMenu.h
*
* This is the Main Menu for the game, I am creating called Nyan Cat The Game.
* It will have the ability to travel throughout the game.
*
* In the main menu you can:
* 1. Play
* 2. How To Play (help menu)
* 3. Credits
*
* Author: Miguel Martin (c) 2011.
*************************************************************************/
#pragma once
#ifndef __NCMAINMENU_H__
#define __NCMAINMENU_H__
#include "Scene.h"
class NCMainMenu : public ge::util::Scene
{
public:
// Main function for the main loop
virtual int MainLoop();
// Initializes variables
virtual int Init();
// Handles user input
virtual void HandleInput(SDL_Event&);
};
#endif // __NCMAINMENU_H__
Code: Select all
#include "NCMainMenu.h"
#include "FPSCounter.h"
#include "MiguelsGameEngine.h"
int NCMainMenu::MainLoop()
{
const ge::util::FPSCounter FPS(20);
SDL_WM_SetCaption("Main Menu!", 0);
SDL_Event event;
while( !isDone() ){
while(SDL_PollEvent(&event)){
// Handle the Input from the user
HandleInput(event);
}
// Limit the Frame-Rate.
FPS.LimitFPS();
}
return 0;
}
int NCMainMenu::Init()
{
return 0;
}
void NCMainMenu::HandleInput(SDL_Event& event)
{
RenderWindow->HandleInput(event);
}
MiguelsGameEngine.h
Code: Select all
/************************************************************************
* MiguelsGameEngine.h
*
* This header file declares a global BaseWindow null pointer. Used to make a
* generic Window to render your graphics.
*
* Author: Miguel Martin. (c) 2011
************************************************************************/
#pragma once
#ifndef __MIGUELSGE_H__
#define __MIGUELSGE_H__
#include "BaseWindow.h"
// The Rendering Window. Use this to Render onto the screen.
// If you would like both Software Rendering and OpenGL rendering abilities.
ge::win::BaseWindow* RenderWindow = 0;
#endif // __MIGUELSGE_H__