Can someone recommend a great tutorial to setup SDL2 in Apple Xcode?

Hi,

We have a working remote Apple Mac Mini(not M1) desktop now.
Can someone recommend a great tutorial to setup SDL2 in Apple Xcode?
(we also use Image, Mixer, & TTF SDL2 support libraries)

The SDL2 game is 100% finished, just want to build source into an Apple Mac executable.

Thanks!

Jesse

  1. Create a regular Mac app, with Objective-C as the language. You don’t need to pick one of the game templates.
  2. Rip out everything ending in .nib, .xib, or .storyboard
  3. In Finder, copy SDL2.framework to the same folder as the .xcodeproj
  4. Project settings, Build Settings tab, set the framework search path to the same folder as the .xcodeproj
  5. Project settings, under the General tab, in the Frameworks, Libraries, and Embedded Content section, hit the plus (+) to add a framework. In the window that pops up, hit Add Other then navigate to SDL2.framework and select it. This tells Xcode to link to it, and also to copy it to your app bundle so users won’t need to have SDL2 installed
  6. Project settings, under Signing & Capabilities:
    – Check “USB” under App Sandbox if you want players to be able to use game controllers
    – Under Hardened Runtime check “Disable library validation” unless you’ve built and signed SDL2.framework yourself
  7. Delete whatever source code Xcode added to the project and replace it with your own.

That should be it.

Hi,

Thanks for the detailed instructions.
I think I am on a newer Xcode, because the steps don’t match my Xcode 13.

Little lost and don’t know how to proceed…

Jesse

Hi,

So I started from the beginning…

I downloaded all the Mac OS X frameworks from the SDL2 site.
I copied:

  • SDL2
  • SDL2_Image
  • SDL2_Mixer
  • SDL2_TTF
    frameworks to:
    /Library/Frameworks

What do I do now with Xcode version 13 ?
When I select create new project in Xcode I see various templates and also the option to create empty.
What do I select?

Been using macOS 12.1 Monterey for 2 days, it’s all new to me.

Jesse “JeZxLee”

Hi,

Google “LazyFoo SDL2” - it’s outdated, but still very helpful.

Jesse

Those are the steps I use with Xcode 13. What isn’t matching?

Don’t put any of them in /Library/Frameworks

Your users won’t have them, and you’ll need to bundle them with your app (which Xcode will do for you, following the directions I gave above)

Like I wrote above, choose the one to create a regular Mac app.

edit: combined into one post

edit: combined into one post, whoops :wink:

Hi,

Ok, I followed all the instructions…

I have a FreeType error now when building(see attached screenshot),

Jesse

1 Like

I also have that error, I’ve been trying to the same thing as you want for the last two days and I can’t find a fix :frowning:

Ok, I think that is solved by using newer Release Candidate of SDL2_TTF.

I have below error now:

CodeSign /Users/jesse/Library/Developer/Xcode/DerivedData/TC4T-macOS-gfrjtvvdkdcrvrdrgfncgouwxhjv/Build/Products/Debug/SDL2_mixer.framework/Versions/A (in target 'TC4T-macOS' from project 'TC4T-macOS')
    cd /Users/jesse/Desktop/TC4T-macOS/TC4T-macOS
    export CODESIGN_ALLOCATE\=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
    
    Signing Identity:     "Apple Development: slnthero@aol.com (BGKL2GRK2A)"
    
    /usr/bin/codesign --force --sign 093CE8B73901EE50F6AD77E432AC53028F982EE0 -o runtime --timestamp\=none --preserve-metadata\=identifier,entitlements,flags --generate-entitlement-der /Users/jesse/Library/Developer/Xcode/DerivedData/TC4T-macOS-gfrjtvvdkdcrvrdrgfncgouwxhjv/Build/Products/Debug/SDL2_mixer.framework/Versions/A

/Users/jesse/Library/Developer/Xcode/DerivedData/TC4T-macOS-gfrjtvvdkdcrvrdrgfncgouwxhjv/Build/Products/Debug/SDL2_mixer.framework/Versions/A: code object is not signed at all
In subcomponent: /Users/jesse/Library/Developer/Xcode/DerivedData/TC4T-macOS-gfrjtvvdkdcrvrdrgfncgouwxhjv/Build/Products/Debug/SDL2_mixer.framework/Versions/A/Frameworks/Opus.framework
Command CodeSign failed with a nonzero exit code

Yeah that’s basically the same error but with SDL2_mixer, this error will happen with every single framework included in sdl2 ttf,mixer,image. My guess is that SDL2 frameworks for macOS are not signed properly, that’s why the error says CodeSign.
Also, signing manually won’t work, I tried it multiple times, I always get errors.

Those are code sign errors. Basically, every single binary inside a framework has to be signed in order for code signing to work, but the code sign tool won’t recursively sign frameworks or app bundles. So, if you have one of the various SDL_* libraries that include frameworks inside their frameworks, you have to manually sign them inside-out, by first signing the inner frameworks (FreeType, etc.) then the SDL_* framework.

Also, apparently (at least for SDL_Mixer) the directory layout inside the framework is kinda weird and the code sign tool has a hard time figuring it out.

Somebody posted a way to get the code sign tool to be able to sign SDL_Mixer a while back, but I can’t find that post now.

Personally, this is part of the reason I use SDL but not any of the SDL_* libraries. Instead of SDL_Image I use stb_image and instead of SDL_TTF I use stb_truetype, which are header-only libraries that don’t have external dependencies (except stb_truetype weakly requires stb_rectpack). STB on GitHub For audio I just use OpenAL.

1 Like

Hi,

Thanks for the information.

I reached out Sam and Ryan about this issue.
Hopefully they can solve it soon.

Jesse

Let me know if you manage to solve the issue

Update: I manually code signed every frameworks’ frameworks (that sounds weird lol), each got signed properly unless SDL2_image, bundle format is ambiguous is the error I get, I’ll maybe try to convert my game from SDL2_image to stb_image as sjr said, if I can’t find solutions.