• Advertisement
Sign in to follow this  

[SOLVED] Using SDL in XCode

This topic is 3230 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, 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]

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
Oh! I just imported the SDLMain.m & .h files into my project. However, now I get these errors when compiling:
Quote:

/Users/Jonas/Desktop/cpp/SDL/../../SDLMain/NIBless/SDLMain.m:8:16: error: SDL.h: No such file or directory
/Users/Jonas/Desktop/cpp/SDL/../../SDLMain/NIBless/SDLMain.m:75: error: 'SDL_Event' undeclared (first use in this function)
/Users/Jonas/Desktop/cpp/SDL/../../SDLMain/NIBless/SDLMain.m:75: error: parse error before 'event'
/Users/Jonas/Desktop/cpp/SDL/../../SDLMain/NIBless/SDLMain.m:76: error: 'event' undeclared (first use in this function)
/Users/Jonas/Desktop/cpp/SDL/../../SDLMain/NIBless/SDLMain.m:76: error: 'SDL_QUIT' undeclared (first use in this function)

*Confused*

By the way, do you use XCode? If so, and if you want, could you please make a working SDL app (nothing fancy, just something that initializes SDL) and send it to my email?

Share this post


Link to post
Share on other sites
ah were getting close :D change line 8 in SDLMain.m from

#import "SDL.h"

to

#import <SDL/SDL.h>

Share this post


Link to post
Share on other sites
Noew I am getting this error:
Quote:

ZeroLink: unknown symbol '__NSConstantStringClassReference'

sdlapp has exited due to signal 6 (SIGABRT).



Share this post


Link to post
Share on other sites
try adding the following frameworks:

Cocoa.framework
AppKit.framework
Foundation.framework

they should be in System/Library/Frameworks/

Share this post


Link to post
Share on other sites
I am still getting the Signal 6 error. Do you use Xcode? If so, would it be possible to create a simple Project that Initializes SDL, and send it to me via email?

Share this post


Link to post
Share on other sites
yes (version 3), and yes, one last thing to try however is disabling zerolink, under the build menu and see what it says when you build it

Share this post


Link to post
Share on other sites
oops just noticed another thing (sorry this seems to be getting very long and convoluted) instead of 'int main()' you should have int 'main(int argc, char* argv[])'

Share this post


Link to post
Share on other sites
I disabled zerolink & change the main functions arguments, however now Im getting this error when trying to build it:
Quote:

/usr/bin/ld: Undefined symbols:
_SDL_Init
_SDL_PushEvent


However, shouldn't
Quote:

int main() {}

work since it is C++?

Share this post


Link to post
Share on other sites
hmm those are strange errors, the problem with 'int main()' and SDL is because of what I was saying earlier, your main function isn't actually the main function anymore SDL renames it to SDL_Main, and in SDLMain.m there is a function 'int main(int argc, char* argv[]) which tries to call SDL_Main(arc, argv), so you have to use the longer version or it won't work correctly

Share this post


Link to post
Share on other sites
Edit: heres the sample project, should work for all versions now hopefully
http://www.mediafire.com/?sharekey=9712aa68860b89d5d2db6fb9a8902bda

Share this post


Link to post
Share on other sites
Could you please send it to my email [the project]

Quote:

jonas [at] amann [dot] co [dot] nz

?

(I am on a public computer, and they block File Sharing sites/etc, and thus I am unable to access mediafire)
Thanks in advance, and for all the effort you put in to fix the problem!

Share this post


Link to post
Share on other sites
Argh...now Im getting errors because Im not on OSX 10.5!
I'll just setup everything like in your project, and hope it works. :)
Thanks again!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement