Sunday, July 5, 2015

SDL 2 (and extensions) on XCode 6 Tutorial

Hey all,

So I ran into an issue recently involving using SDL on Mac OSX and XCode, and would like to provide a tutorial showing my findings.

A Summary:

XCode is not the best IDE in terms of telling you exactly what's going on. Apple forces you to create an app using their frameworks that aren't exactly practical in terms of multi-platform game creation, circumventing this is a real pain and causes a lot of headache.

I'm going to assume that you have some familiarity with XCode, I may skip over some details I consider trivial, like: "how to navigate a project". There are enough tutorials as it is on that subject matter.

4. Enter a name for your project, and create it! Yay! Step one!
5. See the files highlighted in the picture below? See them? Yeah? Delete them, XCode generates those and we don't need them. If you want test cases go ahead, but I'm not keeping them.

2. Download any SDL 2 extensions that you plan to use.
Examples include: SDL_image, SDL_mixer, SDL_ttf
3. Drag and drop the .framework files from each of these downloads to /Library/Frameworks, congratulations, you just installed SDL 2!

This is what my /Library/Frameworks directory looks like.

XCode and SDL 2:

Now that you have XCode, SDL 2, and your project started, we can now configure the project itself! THE FUN PART! (For many definitions of fun.)

So, there's an interesting bug in XCode, where if you try to link a library with unsigned code, XCode will crash. Hard crash. As in, the app forcefully closes. It sucks, really bad. Unfortunately, SDL 2 and its extensions are all unsigned! So I will help you fix that.

1. Open a Terminal and navigate to /Library/Frameworks (that's the 'cd' command for those who don't use the Terminal.)

Yes, my Terminal is black and blue like that.

2. Code Sign all of your SDL 2 frameworks (You may need to have XCode tools installed, there are tutorials on that as well.)

3. The command that you are looking for looks as such:

Modify as needed for other frameworks

Clapping Time!Congratulations! You now have a project ready to write SDL related code in! You can reference SDL just like this:

Give yourself a pat on the back, you just saved yourself a crap ton of time! If you have any questions let me know in the comments, and I'll adjust the tutorial accordingly! This is my first time writing a publicly accessible tutorial about project set up.

If you want to actually draws things, there are MANY tutorials on that subject matter, and would be another tutorial in its own right, for now, I'm gonna leave it to the setting up part.