Issues using SDL2 on Xcode on macOS

You can link to frameworks from command-line programs. You can’t embed them in a command-line program like you can a regular macOS app (aka an app bundle), since a cli program is just a bare binary.

If you want to distribute your Mac app, it needs to be in the form of an app bundle, which Xcode sets up your project to create when you choose the vanilla macOS app template.

Not true. SDL takes care of the stuff that touches macOS directly, which is what you’d otherwise need Objective-C or Swift for. Your app can be written in C, C++, or whatever else. Conversely, you can absolutely write command-line apps in Objective-C or Swift.

I created an Xcode project for a simple SDL2 app. You can see it here.

README.md contains instructions to create your own.

Hopefully the instructions make sense; I didn’t get much sleep and so my brain is fried right now :face_with_spiral_eyes:

Thanks for doing that sjr.

My main app has migrated from 1984 from mini-UNIX on Apple Lisa to Mac Plus through MBPro M2 (Semantics-C, Think-C, Metrowerks, Xcode). It has been a vanilla C binary for more than 30 years (migrating from XVT->SDL2 along the way). I guess it’s time to bundle it up nice and warm!

I’ll let you know how that goes :slight_smile:

Thanks again (sleep quickly).

Bundled.

That was a really good App-creation crib. I migrated my CLI to an App by following your directions and then dragging the required source and other resource groups from my “old” CLI Xcode project to the new App Xcode project.

That introduced sandboxing into the project that continued to get in the way from the default runtime Current Working Directory down to the core OS chdir() command. It was not feasible to copy working files into the sandbox hierarchy (it’s a user-level code generator that needs access to an hierarchy of files per run). There is an approved way to introduce selected disk access to the program by asking the user interactively to chose which file hierarchies are OK to use (or full disk access by having the user choose the volume root). I cheated and turned off sandboxing for the App by modifying the .entitlements file to contain "App Sandbox"... NO.

Now it all works with some Xcode-introduced message litter:

BOOL _NSPersistentUIDeleteItemAtFileURL(NSURL *const __strong) Failed to stat item: file:///<userpath>/Library/Saved%20Application%20State/Champagne.Champagne.savedState/restorecount.plist

CLIENT ERROR: TUINSRemoteViewController does not override -viewServiceDidTerminateWithError: and thus cannot react to catastrophic errors beyond logging them

Thank you so much for your help sjr.

1 Like