Page 1 of 1

[SOLVED]SDL OpenGL linker errors

Posted: Sat Mar 06, 2010 9:38 pm
by eatcomics
So I'm trying to make a space invaders game with SDL and OpenGL. I keep getting these linker errors

Code: Select all

Main.obj : error LNK2019: unresolved external symbol _atexit referenced in function _SDL_main
Main.obj : error LNK2019: unresolved external symbol __imp__printf referenced in function _SDL_main
Main.obj : error LNK2001: unresolved external symbol __fltused
LINK : error LNK2001: unresolved external symbol _mainCRTStartup
I've seen on google that the mainCRTStartup thing means that either I did main in my program wrong, which I'm pretty sure its right

Code: Select all

int main(int argc, char *argv[])
or you have to set your entry point to wWinMainCRTStartup, that didn't work.

as for the others I have no clue. Lots of things have said that its due to not including the libraries right... but I'm pretty sure they are all there I'm linking the following libraries to my project

Code: Select all

sdl.lib sdlmain.lib opengl32.lib glu32.lib
I think that should be all... Here is my code

Code: Select all

#include <stdio.h>
#include <sdl.h>
#include <sdl_opengl.h>
#include <gl/gl.h>

#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600

int main(int argc, char *argv[])
{
	if (SDL_Init(SDL_INIT_EVERYTHING | SDL_OPENGL) < 0)
	{
		printf("Unable to init SDL %s\n", SDL_GetError());
		return 1;
	}
	atexit(SDL_Quit);

	SDL_WM_SetCaption("Sp4c3 1nv4d3rz", NULL);

	//Set icon at the topleft to be this 
	SDL_Surface* image = SDL_LoadBMP("icon.bmp");
	int colorkey = SDL_MapRGB(image->format, 255,0,255);
	SDL_SetColorKey(image, SDL_SRCCOLORKEY, colorkey);
	SDL_WM_SetIcon(image, NULL);
	
	//OGL attributes :P
	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

	SDL_Surface* screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16, SDL_OPENGL);
	if (!screen)
	{
		printf("Unable to set %ix%i video: %s\n", SCREEN_WIDTH, SCREEN_HEIGHT, SDL_GetError());
		return 1;
	}

	//OGL viewport and stuff like buffer clear color
	glViewport(0, 0, screen->w, screen->h);
	glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0); //This will need to be changed...
	glClearColor(0.0, 0.0, 0.0, 0.0);

	//quit?
	bool done = false;

	//main game loop
	while (!done)
	{
		SDL_Event event;
		while (SDL_PollEvent(&event))
		{
			switch (event.type)
			{
       			case SDL_QUIT:
				{
					done = true;
					break;
				}
				case SDL_KEYDOWN:
				{
					if (event.key.keysym.sym == SDLK_ESCAPE)
					{
						done = true;
					}
					break;
				}

			}
		}

	    //Draw GL stuff!
	    glClear(GL_COLOR_BUFFER_BIT);
		glColor3f(1.0f, 1.0f, 1.0f);
		
		glBegin(GL_TRIANGLES);

		    glVertex2f(400.0, 160.0);
			glVertex2f(320.0, 440.0);
			glVertex2f(480.0, 440.0);

		glEnd();

		SDL_GL_SwapBuffers();
	}
	return 0;
}
if anyone has any clue what the problem might be, I would be very grateful... one more thing, I have tried putting this code into a clear project, a clear win32project, and a clear console project... I've been trying to get it to compile for 3 days now...

Re: SDL OpenGL linker errors

Posted: Sat Mar 06, 2010 9:46 pm
by eatcomics
I'm dumb as hell, it would figure, 3 days of trouble, and right after I post here, I'd figure it out

I forgot to put "icon.bmp" in the executables directory! GOD I SUCK

Re: SDL OpenGL linker errors

Posted: Sat Mar 06, 2010 9:49 pm
by Falco Girgis
eatcomics wrote:I'm dumb as hell, it would figure, 3 days of trouble, and right after I post here, I'd figure it out

I forgot to put "icon.bmp" in the executables directory! GOD I SUCK
I'm sorry, but there is no way in FUCK that that could have been your problem.

That would have been a runtime error, segfault, or crash--not a compile error bitching about undefined symbols.

Re: [SOLVED]SDL OpenGL linker errors

Posted: Sat Mar 06, 2010 9:50 pm
by Bakkon
SDL_opengl.h includes gl.h and glu.h for which system you're compiling on, so you could remove that redundant include.

Re: SDL OpenGL linker errors

Posted: Sun Mar 07, 2010 12:22 am
by eatcomics
GyroVorbis wrote:
eatcomics wrote:I'm dumb as hell, it would figure, 3 days of trouble, and right after I post here, I'd figure it out

I forgot to put "icon.bmp" in the executables directory! GOD I SUCK
I'm sorry, but there is no way in FUCK that that could have been your problem.

That would have been a runtime error, segfault, or crash--not a compile error bitching about undefined symbols.
Lol, I was ignoring all default libraies, that was more the problem, you see when I did that it compiled but wouldn't run, so I thought... hm I must have done something wrong, and started a new project, its all good now

Re: [SOLVED]SDL OpenGL linker errors

Posted: Sun Mar 07, 2010 12:22 am
by eatcomics
Bakkon wrote:SDL_opengl.h includes gl.h and glu.h for which system you're compiling on, so you could remove that redundant include.
done that

I was trying to fix my earlier problems

Re: [SOLVED]SDL OpenGL linker errors

Posted: Sun Mar 07, 2010 9:15 am
by Protimus
eatcomics wrote:

Code: Select all

SDL_Init(SDL_INIT_EVERYTHING | SDL_OPENGL)
I don't think that SDL_OPENGL should be here :)

Re: [SOLVED]SDL OpenGL linker errors

Posted: Sun Mar 07, 2010 3:38 pm
by eatcomics
Protimus wrote:
eatcomics wrote:

Code: Select all

SDL_Init(SDL_INIT_EVERYTHING | SDL_OPENGL)
I don't think that SDL_OPENGL should be here :)
Correct you are sir, once more trying something!

But now I've got the project all split up, and its looking sexy :D