LNK Error, can't figure out?

Started by
5 comments, last by BFMVfavorite 16 years, 9 months ago
Hey all, I don't know what the deal is, but I'm using MSVC++.NET 2003 and I keep getting this error:

LIBCD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup
Debug/test5.exe : fatal error LNK1120: 1 unresolved externals
I'm just making a basic SDL/OpenGL window, here's my code for that:

#define WIN32_LEAN_AND_MEAN
#define EXTRA_LEAN

#include <windows.h>
#include <SDL/SDL.h>
#include <gl/gl.h>
#include <gl/glu.h>

SDL_Event event;

void Render();
int main(int argc, char *argv[]);


int main(int argc, char *argv[]){

  SDL_Init(SDL_INIT_VIDEO);
  SDL_SetVideoMode(1024,768, 0, SDL_OPENGL | SDL_HWSURFACE );
  SDL_WM_SetCaption("SDL Window", "SDL Window");

  glViewport(0, 0, 1024, 768);
  glMatrixMode(GL_PROJECTION);		// set projection matrix current matrix
  glLoadIdentity();					// reset projection matrix

			// calculate aspect ratio of window
			gluPerspective(54.0f,(GLfloat)1024/(GLfloat)768,1.0f,1000.0f);

			glMatrixMode(GL_MODELVIEW);			// set modelview matrix
			glLoadIdentity();	
  	        

  int done;
  for(done = 0; !done;){
    
    SDL_PollEvent(&event);
   
    Render();
    
    //Keyboard input.
    if(event.key.keysym.sym == SDLK_ESCAPE)
      done = 1; 
     
    if(event.type == SDL_KEYDOWN)
	{
	}
      
    if(event.type == SDL_KEYUP)
	{
    }
      
      
    if(event.type == SDL_QUIT){done = 1;}
}
  SDL_Quit();
  return 0;
}

void Render()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		
	glEnable(GL_DEPTH_TEST);
	glLoadIdentity();
	gluLookAt(0,0,40,0,0,0,0,1,0);
	glPushMatrix();
	
    
	glFlush();
	SDL_GL_SwapBuffers();
}


I tried it both with a Win32 Project and Console Project, the only difference is the Win32 project gives me a WinMain error instead of main. I'm not including those cursed precompiled headers, and I'm linking all the necessary libraries: opengl32.lib glu32.lib sdl.lib. So, what's my problem? Thanks a bunch, Nathan --
Advertisement
It should be a console project.
Make sure your project configuration is set to use the "multi-threaded debug dll" library, and also remember to link to the required SDL .lib files (SDLmain.lib and SDL.lib)

And as a side note, conventionally instead of
int done;  for(done = 0; !done;){

You should write
bool quit = false;while(!quit){

Quit is a bit more intuitive than 'done', and the while loop is more compact and easier to read :)

Also in your render function you have glPushMatrix(); This should always be matched up with a corresponding glPopMatrix(); although in this case, you should take out the glPushMatrix() completely as it isn't doing anything :)

Regards,

[Edited by - Albatross3 on July 23, 2007 9:44:34 PM]
Followed both of your instructions, yet I'm still getting the same error...I really hate LNK errors, they always seem to be unsolvable. Any other suggestions?

Thanks a bunch though albatross
--Nathan

--
Sorry I posted a half assed, wrong solution before, and took ages to edit. Re-read and try the above :)
The edit only cleans up my code, no error solving....eh I pay $100 for this and now I'm thinking of going back to Dev-C++ after 2-3 years of stupid LNK errors that make no sense. Someone please give me a solution!

Thanks again though albatross
--Nathan

--
Sorry I don't know what else to suggest - this does seem to be a fairly common thing when beginning SDL, and almost always the problem lies with either forgetting to link to the SDL libraries, or not setting the project to use the multi-threaded (debug) DLL runtime library :S

Maybe someone else will come along and lend a hand...
Well, I solved it, it was some weird setting in my subsystems preferences. I was just messing around with it and it worked, but thanks for the help albatross!

--Nathan

This topic is closed to new replies.

Advertisement