[SOLVED] Using SDL in XCode

Started by
22 comments, last by pseudobot 15 years ago
Hi, newbie here. I just started using XCode/C++ a few days ago, and thus don't know too much about it. One of the problems I have at this moment is adding a libary, in my case the SDL (SimpleDirect Media Layer) to my Xcode project. Right now, when I import the SDL framework. However, I get the error:
Quote: sdl.h - No such file or directory
How would my code find the SDL.h file in the framework? Sorry again, Im very new to this, so please bear with me. [Edited by - pseudobot on April 21, 2009 12:07:00 AM]
Advertisement
try #include <SDL/SDL.h>

also there might be an issue in the SDLMain file, I can't remember exactly but if you get any more errors just replace 'sdlfilename.h' with <SDL/sdlfilename.h>, all this is assuming you've added SDL.framework to your project
For some reason, it compiles fine now, but I get this error:
Quote:
sdlapp has exited due to signal 10 (SIGBUS).


The apps code is:
#include <iostream>#include <SDL/SDL.h>using namespace std;int main() {	if (SDL_Init(SDL_INIT_VIDEO) == -1) {		cout << "Could not initalize SDLVideo!";	}		else {		cout << "SDL Initalized!";	}}

Please help.

have you included SDL_Main? try adding

#include <SDL/SDL_main.h>

also, you will need to put the files SDLMain.m and SDLMain.h to you project, they should be included with your download of SDL
Im still getting the Signal 10 error... :(
hmm that is strange, I would try reinstalling SDL, and trying a new XCode project, are you using the SDL application templates, or starting your project from scratch?
I started the project from scratch. Here is how it looks (in case it might help tracking down the mistake)
(Please excuse the size)
SDL project
well I notice you don't have SDLMain.m in there, this file is actually pretty important because of the way SDL works. What it does is defines it's own main function (which does a lot of setup before you even get to your own main function let alone your call to SDL_Init) it also has a define that looks like this:

#define main SDL_main

this changes your functions name so that your apps real entry point is in SDLMain.m,
I am a little surprised that your compiler isn't complaining about "_main" being undefined
There's only SDL_main.h, no SDLMain.m file in the framework. So, this means I should get the SDL_main.h file out of the framework? Thanks for your help so far btw.
actually, if you download the file under 'development libraries' from the SDL site, there should be a folder inside callde 'SDLMain', in there you want the folder 'NIBless', and there should be SDLMain.m, and SDLMain.h

Quote:Original post by pseudobot
Thanks for your help so far btw.

Glad to help, I remember how much of a headache I had when I tried setting this up for my first time as well :D

This topic is closed to new replies.

Advertisement