user1185305
user1185305

Reputation: 895

How to setup SDL2 with XCode 4.6 and OS X 10.8

How to set up SDL2 with MAC OS X 10.8 and XCode 4.6 or later versions?

I have managed to build SDL2 and assume to have all the files I need. Where should I place my library files and setup XCode project to be able to build and run a simple example?

Upvotes: 4

Views: 2669

Answers (1)

Agi Hammerthief
Agi Hammerthief

Reputation: 2134

  1. Download latest SDL fromework from here (scroll down to “Development Libraries").
  2. Copy the SDL2.framework bundle to /Library/Frameworks (may require root permissions)
  3. If XCode crashes due to code-signing issues, run this from terminal: codesign -f -s - /Library/Frameworks/SDL2.framework/SDL2
  4. Create a Cocoa project in XCode.
  5. Strip out superflous files and frameworks as shown in the below images:
  6. Select the project name at the top of the sidebar, then “Build Settings” in the main pane. Set “Precompile Prefix Header” to “No”. Clear the path in the “Prefix Header” setting, leaving that setting empty.
  7. Expand the project targets drawer, then select the test target and click the “-” button. When prompted, confirm you really want to delete this target.
  8. Add the SDL framework bundle: You’ll see SDL2.framework. Add it.
  9. Select the project from the left sidebar, then choose “Build Phases” for your app target. Click the “+” button under “Copy Bundle Resources”, then choose SDL2.framework to add.
  10. Fill in main.c with the code below:
  11. Compile and run with Command + R. If everything worked, you’ll see SDL_Init success! output in the lower pane of Xcode.

superfluous files superflous libraries

#include <SDL2/SDL.h>

int main(int argc, const char * argv[]){
    if(SDL_Init(SDL_INIT_EVERYTHING) != 0) {
        puts("SDL_Init error");
        return -1;
    }
    else {
        puts("SDL_Init success!");
        return 0;
    }
}

Source: SDL2 on Mavericks OS X

Upvotes: 1

Related Questions