[SOLVED]SDL OpenGL linker errors

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

[SOLVED]SDL OpenGL linker errors

Post 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...
Last edited by eatcomics on Sat Mar 06, 2010 9:46 pm, edited 1 time in total.
Image
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: SDL OpenGL linker errors

Post 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
Image
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: SDL OpenGL linker errors

Post 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.
User avatar
Bakkon
Chaos Rift Junior
Chaos Rift Junior
Posts: 384
Joined: Wed May 20, 2009 2:38 pm
Programming Language of Choice: C++
Location: Indiana

Re: [SOLVED]SDL OpenGL linker errors

Post 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.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: SDL OpenGL linker errors

Post 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
Image
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: [SOLVED]SDL OpenGL linker errors

Post 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
Image
Protimus
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 25
Joined: Mon Jun 01, 2009 9:27 pm
Current Project: Game Engine
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: Jackson, AL
Contact:

Re: [SOLVED]SDL OpenGL linker errors

Post by Protimus »

eatcomics wrote:

Code: Select all

SDL_Init(SDL_INIT_EVERYTHING | SDL_OPENGL)
I don't think that SDL_OPENGL should be here :)
Judge not a man by his language but by his use of the language.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: [SOLVED]SDL OpenGL linker errors

Post 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
Image
Post Reply