How to statically link SDL (Objective-C) on Mac?

Hi! I’m trying to prepare my Zig application for, like, CI/CD (a pair of acronyms I finally looked up the meaning of yesterday, so you know I’m out of my depth).

Currently I depend on five C/C++ libraries. Since harmonizing dependencies across platforms has proven tricky, I’d like to statically link as much as possible.

My (limited) understanding so far is that to do this in build.zig I need to find or create a .a file for each of these dependencies (not so bad), add that to my executable (exe in build.zig) with exe.addObjectFile("/path/to/libname.a") and then link the dependencies of the dependencies.

I think even that part is maybe not so bad. The one part I’m stuck on is when linking SDL on Mac, which needs to link some Objective-C code. copypasta-ing the Frameworks to link from Andrew’s SDL fork gets me pretty far, but I’m still getting a host of “undefined reference to symbol” complaints from the compiler, most of which start _objc_msgSend. Adding exe.linkSystemLibrary("objc") doesn’t appear to help one way or the other.

Any hints would be very welcome!

If you want an example of how to use my SDL package, here is an example project:

I tested it on macOS! If you run into trouble please feel free to file a zig-sdl issue.

1 Like

golly, that took out a lot of my problems in one fell swoop! now to try and mop up / convert other things to this system.