How to set up a SDL 2 project for OS X in Xcode 4

SDL 2 doesn’t come with a proper project template for Xcode, so if you’re developing on a Mac for OS X or iOS you need to create one from scratch or you have to reuse an example project provided with the SDL code package.

The whole process is not rocket science, but as it takes few minutes you probably want to create an empty project to use as template for all your future ones, in this post I’m going to show you how to do that.

Before even starting

It’s probably worth to mention that this howto is based on XCode 4.6.3 and SDL 2.0.0 running on OS X 10.8.4, your configuration could be different and things could change a bit in the next few months, but for now this should do the trick.

Obviously you need to download SDL 2 and eventually any other sub-library

15 Comments

  1. Apateona

    Very clean explained.
    Thank you very much !

    Reply
  2. Diogo Muller

    Thanks! That helped a lot!

    Reply
  3. kouky

    Thank you for the tutorial,
    I can compile the test code unfortunately no black window appear, the app icon just bounces for 5 seconds and then app closes.
    Any Hints?

    Reply
    1. r00t (Post author)

      I’d start checking the debug panel, if there’s any problem with SDL you should be able to get a better description using SDL_GetError()

      Reply
    2. Nico Cvitak

      Hey I’ve got a similar problem with the window not opening, and the app icon just bouncing. I was just wondering if you figured out the problem yet.

      Reply
  4. tor

    Wow, I’m completely new to OS X and XCode, but with this tutorial I got the example program to work!
    Thanks Dave!

    Reply
  5. Yevgeni Zolotko

    Thank you, extremely helpful!

    Reply
  6. M787

    I’ve a problem… I deleted the file named SDL2_template-Prefix.pch, and when I try to start the template, Xcode give me an error about this… How can I solve?

    Reply
    1. M787

      Ok, sorry, I didn’t saw that part of the tutorial 🙁

      Reply
  7. Dez

    I’m followed all the steps and i got it to compile without error, but it won’t stop crashing. I’m using Xcode 5.. do you think that could be the problem?

    Reply
    1. Dez

      I followed not I’m followed haha

      Reply
    2. Will

      I have the same problem. Running it actually crashes Xcode. Might be a problem with SDL? Here is the Xcode crash report:

      Process: Xcode [53654]
      Path: /Applications/Xcode.app/Contents/MacOS/Xcode
      Identifier: com.apple.dt.Xcode
      Version: 5.1.1 (5085)
      Build Info: IDEFrameworks-5085000000000000~10
      App Item ID: 497799835
      App External ID: 520942841
      Code Type: X86-64 (Native)
      Parent Process: launchd [180]
      Responsible: Xcode [53654]
      User ID: 501

      PlugIn Path: /Library/Frameworks/SDL2.framework/Versions/A/SDL2
      PlugIn Identifier: org.libsdl.SDL2
      PlugIn Version: 2.0.3 (2.0.3)

      Date/Time: 2014-06-18 10:03:51.951 -0400
      OS Version: Mac OS X 10.9.3 (13D65)
      Report Version: 11
      Anonymous UUID: 83AF7DBE-870D-B7DA-8E18-14C283B528E3

      Sleep/Wake UUID: 85193FBC-2B9F-4454-9FA4-8BF6A2474208

      Crashed Thread: 25

      Exception Type: EXC_BAD_ACCESS (Code Signature Invalid)
      Exception Codes: 0x0000000000000032, 0x00000001135f9000

      kernel messages:
      -2 sec CODE SIGNING: cs_invalid_page(0x1135f9000): p=53654[Xcode] final status 0x1000200, denying page sending SIGKILL
      -2 sec CODE SIGNING: process 53654[Xcode]: rejecting invalid page at address 0x1135f9000 from offset 0x1000 in file “/Library/Frameworks/SDL2.framework/Versions/A/SDL2” (cs_mtime:1394937310.0 == mtime:1394937310.0) (signed:1 validated:1 tainted:1 wpmapped:0 slid:0)

      Reply
      1. Davide Coppola (Post author)

        it seems you’re having some problem with the code signing.
        Try to not code sign your app and rebuild.

        Reply
    3. Davide Coppola (Post author)

      Just tried in Xcode 5 and it worked just fine.

      Reply
  8. Fabio

    Thanks for the explanation Davide.

    I have it working on Xcode 6 without any issues. I was having the same issue as Will mentioned above. The only fix for me was to build the Framework from scratch, just simply

    1. hg clone http://hg.libsdl.org/SDL
    2. Compile the “Framework” target in Xcode/SDL/SDL.xcodeproj
    3. Copy framework to /Library/Frameworks

    Done.

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *