Sign in to follow this  

Problem with Lazy Foo Game Programming Tutorial

This topic is 674 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 everyone!

 

I'm trying out Lazy Foo' Beginning Game Programming 2.0

 

I just pasted the first program, just to check if it works. I'm using Visual Studio 2015 with the latest SDL libraries.

 

This is the code

/*This source code copyrighted by Lazy Foo' Productions (2004-2015)
and may not be redistributed without written permission.*/

//Using SDL and standard IO
#include <SDL.h>
#include <stdio.h>

//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;

int main(int argc, char* args[])
{
	//The window we'll be rendering to
	SDL_Window* window = NULL;

	//The surface contained by the window
	SDL_Surface* screenSurface = NULL;

	//Initialize SDL
	if (SDL_Init(SDL_INIT_VIDEO) < 0)
	{
		printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
	}
	else
	{
		//Create window
		window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
		if (window == NULL)
		{
			printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
		}
		else
		{
			//Get window surface
			screenSurface = SDL_GetWindowSurface(window);

			//Fill the surface white
			SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF));

			//Update the surface
			SDL_UpdateWindowSurface(window);

			//Wait two seconds
			SDL_Delay(2000);
		}
	}

	//Destroy window
	SDL_DestroyWindow(window);

	//Quit SDL subsystems
	SDL_Quit();

	return 0;
}

and I'm getting an error

fatal error LNK1169: one or more multiply defined symbols found

Looking on the net I found out this is a general error, let's say...

Everything was set ok, Linker and everything else.

I've tried also lesson number 2 and it's the same error.

 

Could some guide me to way to fix the code and make it work?

 

Thanks!

Share this post


Link to post
Share on other sites

LATER EDIT:

 

it was mostly my fault. It's my second time using Visual Studio (used to work with Xcode but since most of the game programming tutorials are for Windows, I switched to a Windows PC) and even though there was only one project started, I had 2 files opened which both had an

int main ()

in them, hence the error ....

Share this post


Link to post
Share on other sites

I'm not a Windows expert, but I think the problem is the usage of the main(…) function. That is *nix style, but in Windows you have to use the WinMain(…) or wWinMain(…) function instead. Since you do not do so, your main(…) and a main(…) within a commonly linked object file do collide.

Edited by haegarr

Share this post


Link to post
Share on other sites

it was mostly my fault.

 
I try to always assume it is my fault. When I was a beginner, 99.99% of the time it was my fault, regardless of what it looked like, even when it seemed "impossible".
And even when I become more experienced, 90%, it's still my fault. tongue.png 
 
As it stands, the title of this thread makes it sound like Lazy Foo's tutorial is broken, which wasn't actually the case. smile.png 
 

I'm not a Windows expert, but I think the problem is the usage of the main(…) function. That is *nix style, but in Windows you have to use the WinMain(…) or wWinMain(…) function instead. Since you do not do so, your main(…) and a main(…) within a commonly linked object file do collide.

 
SDL has #define main SDL_main, which gets called from its own WinMain.

Share this post


Link to post
Share on other sites

 Sure about that?  From the  sdl.org site:  http://wiki.libsdl.org/MigrationGuide

There's no SDL_main! Well, okay, there is, and it now does what it was always meant to: be a small piece of code that hides the difference between main() and WinMain() on Windows. There's no initialization code in it, and it's completely optional. This means you can use SDL without it taking over your mainline, which is nice for plugins that use SDL, or scripting languages with an SDL module. All the stuff you'd want the 1.2 SDL_main for is now in SDL_Init() where it belongs.

I don't use windows, so I have no idea about this (to me) weird WinMain invention by Microsoft, but SDL 2 has changed things there.

Share this post


Link to post
Share on other sites


I try to always assume it is my fault. When I was a beginner, 99.99% of the time it was my fault, regardless of what it looked like, even when it seemed "impossible".
And even when I become more experienced, 90%, it's still my fault. tongue.png

As it stands, the title of this thread makes it sound like Lazy Foo's tutorial is broken, which wasn't actually the case. smile.png

 

Not saying that is broke , just wanted to make the thread to-the-point as possible :)

Share this post


Link to post
Share on other sites

This topic is 674 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