Sign in to follow this  

Problem getting SDL application to run properly

This topic is 2494 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, I've recently decided to try and learn SDL and C++. So I found this great list of tutorial at: [url="http://www.lazyfoo.net/SDL_tutorials/lesson01/index2.php"]http://www.lazyfoo.n...on01/index2.php[/url]

However, when I try to do the first lesson I type this into the main file (SDLmain.h):
[code]/* SDLMain.m - main entry point for our Cocoa-ized SDL app
Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
Non-NIB-Code & other changes: Max Horn <max@quendi.de>

Feel free to customize this file to suit your needs
*/

#import <Cocoa/Cocoa.h>
#include "SDL/SDL.h"

@interface SDLMain : NSObject
@end

int main( int argc, char* args[] )
{
//The images
SDL_Surface* hello = NULL;
SDL_Surface* screen = NULL;

//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );

//Set up screen
screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );

//Load image
hello = SDL_LoadBMP( "/Users/Fenhopi/Downloads/hello.bmp" );

//Apply image to screen
SDL_BlitSurface( hello, NULL, screen, NULL );

//Update Screen
SDL_Flip( screen );

//Pause
SDL_Delay( 2000 );

//Free the loaded image
SDL_FreeSurface( hello );

//Quit SDL
SDL_Quit();

return 0;
}
[/code]

When I hit build and debug, I get this error:
[quote]Command /Developer/usr/bin/gcc-4.2 failed with exit code 1
[/quote]

And this warning:
[quote]
ld: warning: directory '/Users/Fenhopi/Library/Frameworks' following -F not found

ld: duplicate symbol _SDL_main in /Users/Fenhopi/Documents/SDL TEST/build/SDL TEST.build/Debug/SDL TEST.build/Objects-normal/i386/main.o and /Users/Fenhopi/Documents/SDL TEST/build/SDL TEST.build/Debug/SDL TEST.build/Objects-normal/i386/SDLMain.o
[/quote]

Any ideas/suggestions?

Thanks in advance,
Fenhopi

Share this post


Link to post
Share on other sites
Add some error-checking; in particular, check the return value of SDL_LoadBMP() to make sure it's valid. (Often these sorts of problems are related to asset locations and what the current working directory is set to.)

Share this post


Link to post
Share on other sites
[quote name='fenhopi' timestamp='1298016198' post='4775756']
How would I check the return value of SDL_LoadBMP()? Just add return 0; under it?
[/quote]
No, 'return 0' would just end execution of the program at that point (and, it wouldn't tell you anything about whether or not SDL_LoadBMP() succeeded).

If you look at the docs for SDL_LoadBMP(), you'll see that it returns NULL if there was an error. So, you'll want to compare the value returned by the function to NULL, and take appropriate action if it is indeed NULL.

If that's still not clear, post back and I'll try to provide some more info.

Share this post


Link to post
Share on other sites
[quote name='bensmith87' timestamp='1298022967' post='4775778']
Should it not be in a "c file", as in SDLmain.c?
[/quote]
I think the OP actually meant SDLmain.m, rather than .h.

Share this post


Link to post
Share on other sites

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