1

Possible Duplicate:
Compiling with int main(void) fails; main(int argc, char *argv[]) succeeds. Why?

I am making a simple game engine using OpenGL and SDL. All the initialization code for SDL and OpenGL is in a dll. The application then simple calls the function to initialize everything. The dll is compiled and had no issues but when I try and compile an application referencing the dll it doesn't work. It says I have an Undefined reference to `WinMain@16'. I initially thought this was because it was set as a win32 app and I just needed to swap it over to console app.

Turns out it was already on console app. So why am I getting this error? Here is the code for the application:

#include "GameManager.h"

int main()

{

GameManager gameManager;

gameManager.EngineStartUp(480, 640);

return 0;

}

And here is the code for the dll:

#include "GameManager.h"
#include <iostream>
#include "SDL/SDL.h"
#include "gl/gl.h"
#include "gl/glu.h"

GameManager::GameManager()
{
    //ctor

}

GameManager::~GameManager()
{
    //dtor
}

//Initializes OpenGL and SDL
bool GameManager::EngineStartUp(int WindowHeight, int WindowWidth)
{
   if(SDL_Init(SDL_INIT_EVERYTHING) < 0) {
        return false;
   }
   if((Surf_Display = SDL_SetVideoMode(WindowWidth, WindowHeight, 32, SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER | SDL_OPENGL)) = NULL){
        return false;
   }

   glClearColor(0.415f, 0.432f, 1.0f, 1);
   glClearDepth(1.0f);

   glViewport(0, 0, WindowWidth, WindowHeight);

   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();

   glOrtho(0, WindowWidth, WindowHeight, 0, 1, -1);

   glMatrixMode(GL_MODELVIEW);

   glEnable(GL_TEXTURE_2D);

   glLoadIdentity();

   return true;
}
Community
  • 1
  • 1
DavidColson
  • 8,387
  • 9
  • 37
  • 50
  • how about creating a new project and copy the codes to the new project? – Alvin Wong Jul 01 '12 at 12:46
  • Change `int main()` to `int main(int argc, char* argv[])` and link with SDL_main. See here: http://stackoverflow.com/questions/8673378/compiling-with-int-mainvoid-fails-mainint-argc-char-argv-succeeds-why/8673825#8673825 – jrok Jul 01 '12 at 12:47
  • May I ask, why you take this overly complicated route? What's wrong with putting the whole engine front end into the main executable and just the backend stuff into DLLs? BTW, of your so called initialization code, most of it actually belongs into the drawing loop (namely everything starting with gl…). – datenwolf Jul 01 '12 at 15:09
  • Becuase I want the engine to be seperate from the game code to ensure end users don't have to mess around with the low level stuff. With regards to the loop you are correct I have already changed it – DavidColson Jul 01 '12 at 15:40

0 Answers0