Sign in to follow this  

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

This topic is 4164 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Guest 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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4164 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this