-
Notifications
You must be signed in to change notification settings - Fork 0
macOS
Non-Mac specific code, like portable C, should run fine on newer and older versions of macOS than it was compiled on.
Mac-specific code, like that using the Objective-C OS APIs, won't run on older OS versions. Fortunately, you can select an older "deployment target" when compiling by using an environment variable: for example, export MACOSX_DEPLOYMENT_TARGET=10.3
to compiler for >=10.3.
(Apple reference: Configuring a Project for SDK-Based Development)
MacOS calls shared libraries "dylibs".
Every dylib has an ID, which is a path describing where the dylib can be found. When something is compiled which depends on a dylib (either an executable or another dylib) the linker copies the ID of the dylib into a table in that new exe/dylib's metadata. This path within the table is called an install name. At run time, the dynamic linker looks at the install names to find libraries.
IDs and install names can both be changed with install_name_tool(1).
You can use special variables @executable_path, @load_path, and @rpath in an install name.
(The rpaths are a set of paths stored in the exe. @rpath in an install name will try each of these paths, effectively giving some control of the library search to whoever compiles the exe. rpaths can be given at compile time or changed with install_name_tool
.)
Overall, you have quite a few options for relocating and bundling libraries: you can set their IDs at compile time and not touch any install names at all; or leave the IDs as default and then override all the install names recursively; or any mixture of the two. See auriamg/macdylibbundler for a tool which does all this automatically.
- Fun with rpath, otool, and install_name_tool | by Chris Hamons
- xcode - install_name_tool difference between -change and -id - Stack Overflow
Homebrew is a package manager with a simple declarative build format. It's a good way of obtaining dependencies and build tools.
Pre-compiled Homebrew bottles are built without setting the deployment target, so some libraries will require modification. You can take the formula file from homebrew-core and add ENV['MACOSX_DEPLOYMENT_TARGET'] = '10.3'
to the top of the install
method. Then run brew install --build-from-source ./my-formula.rb
.
As discussed, not every library needs this to be compatible; for example, SDL2 does, but SDL2_image doesn't, nor do any of the image codec libraries it depends on.
- Mac app bundles
- Homebrew formulae