Adding Embedded Binaries
8.6. Can I Add Embedded Binaries (dylibs, Frameworks) into My App?
Yes, you can embed dynamic libraries (.dylib
files) and frameworks (.framework
bundles) within your application package. This is often necessary for including third-party code that isn't available as static libraries or when creating app extensions.
Apple's guidelines generally require that any non-system dynamic libraries or frameworks your app uses must be embedded within the app's bundle.
How Embedding Works:
When you embed a binary, it's copied into a specific location within your app bundle (e.g., the Frameworks
directory for frameworks). The main executable of your app is then linked in such a way that it knows to look for these embedded binaries at runtime.
Steps to Embed Binaries (General Approach):
The exact method for configuring this within the Darwin Build Environment's make.cmd
might involve specific linker flags or custom steps in a pre-packaging script. Here's a conceptual overview, which you'd adapt to the build system:
Place Binaries in Your Project:
Copy the
.dylib
or.framework
you want to embed into a known location within your project directory (e.g., aVendor
orExternalLibs
subfolder).
Linker Flags (
DBE_LDFLAGS
):You'll need to tell the linker:
Where to find the library at link time: This might still involve an
-L
path to the library if you're linking against its headers/stubs.The library to link: Using
-l
or by directly specifying the path to the dylib/framework's binary.Runtime Search Path (
@rpath
): Crucially, you need to set the runtime search path for your main executable so it can find the embedded binaries. This often involves linker flags like-rpath @executable_path/Frameworks
(for frameworks inYourApp.app/Frameworks/
) or-rpath @executable_path/
(if dylibs are in the same directory as the executable, though less common for frameworks).You may also need flags to instruct the linker to copy the framework/dylib into the bundle, such as
-embed <library_name>
or similar, depending on the specific linker capabilities exposed byld64
.
Code Signing:
Embedded binaries (dylibs and frameworks) must also be code-signed with your identity. The build system should handle this if correctly configured, ensuring that both the main app and any embedded components are signed.
make.cmd
Configuration:You would modify
DBE_LDFLAGS
in yourmake.cmd
to include the necessary flags.If the build system doesn't automatically handle copying the binaries into the correct bundle location (e.g.,
YourApp.app/Frameworks/
), you might need to use a Pre-Packaging Script to perform this copy operation before the final code signing of the bundle.
Example (Conceptual DBE_LDFLAGS
for embedding a framework):
rem Assume MyFramework.framework is in a "Frameworks" subdir of your project
rem and needs to be copied to YourApp.app/Contents/Frameworks/
set DBE_LDFLAGS=-F./Frameworks -framework MyFramework -Wl,-rpath,@executable_path/../Frameworks
Last updated