need help with SDL in Visual C++ 2003(solved)

Started by
4 comments, last by SiCrane 17 years, 9 months ago
hi, im writing a game engine using C++, SDL and OpenGL. i remembered to link it against SDL.lib, SDLmain.lib, and OpenGL32.lib and to set the runtime library to multithreaded DLL and to include SDL.h and GL/gl.h in every file, but for some reason, the linker still gives me this error:
Quote: Lobster error LNK2019: unresolved external symbol _SDL_main referenced in function _main
here is the source code to main, which seems to be the problem:
[source lang = 'C++']
// Lobster.cpp : Defines the entry point for the console application.
//

#include "lobster.h"
#include "targa.h"

char gExiting;

int main(int argc, char *argv)
{
	LOB_KEYSTATE keystate;
	LOB_MOUSESTATE mousestate;
	SDL_Event event;
	LOB_POINTI resolution;

	init();

	gExiting = FALSE;

	if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO |SDL_INIT_JOYSTICK))
	{
		printf("Error in SDL_INIT(): %s\n", SDL_GetError());
		return 0;
	}

	const SDL_VideoInfo *VideoInfo;
	VideoInfo = SDL_GetVideoInfo();

	if (!VideoInfo)
	{
		printf("Error while attempting to call SDL_GetVideoInfo: %s\n", SDL_GetError());
		return FALSE;
	}

	resolution.x = LOB_WIDTH;
	resolution.y = LOB_HEIGHT; //TODO: Let user pick the resolution

	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_ALPHA_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	
	//TODO: Let the user choose to start in a window
	if (SDL_SetVideoMode(resolution.x, resolution.y, VideoInfo->vfmt->BitsPerPixel, SDL_OPENGL | SDL_FULLSCREEN) == 0)
	{
		printf("Error:Call to SDL_SetVideoMode() failed: %s\n", SDL_GetError());
		return FALSE;
	}

//Main program loop
	while (!gExiting)
	{   
		
		
		
		//Input subsystem
		while (SDL_PollEvent(&event))
		{
			switch (event.type)
			{
			case SDL_KEYDOWN:
				keystate.prev = keystate.now;
				keystate.now.Keys = event.key.keysym.sym;
				keystate.now.Mods = event.key.keysym.mod;
				keystate.now.IsKeyPressed = TRUE;

				HandleKeys(keystate);
				break;

			case SDL_KEYUP:
				keystate.prev = keystate.now;
				keystate.now.Keys = event.key.keysym.sym;
				keystate.now.Mods = event.key.keysym.mod;
				keystate.now.IsKeyPressed = FALSE;

				HandleKeys(keystate);
				break;

			case SDL_MOUSEBUTTONDOWN:
				mousestate.prev = mousestate.now;
				mousestate.now.xPos = event.button.x;
				mousestate.now.yPos = event.button.y;

				switch (event.button.button)
				{
				case SDL_BUTTON_LEFT:
					mousestate.now.LeftButton = DOWN;
					break;
				case SDL_BUTTON_RIGHT:
					mousestate.now.RightButton = DOWN;
					break;
				case SDL_BUTTON_MIDDLE:
					mousestate.now.MiddleButton = DOWN;
					break;
				default:
					break;
				} //switch (event.button.button)

				HandleMouse(mousestate, NULL);
				break;

			case SDL_MOUSEBUTTONUP:
				mousestate.prev = mousestate.now;
				mousestate.now.xPos = event.button.x;
				mousestate.now.yPos = event.button.y;

				switch (event.button.button)
				{
				case SDL_BUTTON_LEFT:
					mousestate.now.LeftButton = UP;
					break;
				case SDL_BUTTON_RIGHT:
					mousestate.now.RightButton = UP;
					break;
				case SDL_BUTTON_MIDDLE:
					mousestate.now.MiddleButton = UP;
					break;
				} //switch (event.button.button)
				HandleMouse(mousestate, NULL);
				break;

			case SDL_MOUSEMOTION:
				mousestate.prev = mousestate.now;
				mousestate.now.xPos = event.motion.x;
				mousestate.now.yPos = event.motion.y;
				mousestate.now.xVel = event.motion.xrel;
				mousestate.now.yVel = event.motion.yrel;
				HandleMouse(mousestate, NULL);
				break;

/*			case SDL_BUTTON_WHEELUP:
				HandleMouse(mousestate, UP);
				break;

			case SDL_BUTTON_WHEELDOWN:
				HandleMouse(mousestate, DOWN);
				break;*/

			default:
				break;
			}


		}
	}
	SDL_Quit();
	return TRUE;
	}



can someone please help me? thanks in advance for all your help.
Advertisement
char ** argv
that fixed it. thanks^
I am new to this programming biz, but I am just curious. In a lot of other code examples I have seen, people use char *argv[]. Is there any difference between the two? Why would you want to dereference twice if it's only a list of arguments?
Quote:Original post by Anonymous Poster
I am new to this programming biz, but I am just curious. In a lot of other code examples I have seen, people use char *argv[]. Is there any difference between the two? Why would you want to dereference twice if it's only a list of arguments?


As a parameter to a function, char *argv[] and char **argv are identical to the compiler. Apart from the line in mains signature, they are identical in use in either form.
char *[] is an array of pointers to char. char ** is a pointer to a pointer to char. There's an implicit conversion between the two that make the two compatible as arguments. In type theory, there's more of a difference, but most of those differences are language lawyer details.

In any case, the reason why it's char ** or char *[] is that multiple arguments can be passed to the program argv[0] is one char *, that can be interpreted as a null terminated character string, but argv[1] is a different char * that refers to a different string, and argv[2] yet another string.

This topic is closed to new replies.

Advertisement