Static vs Dynamic Framework Dispatching (Part 3 of 3): Debug, Release, @rpath, and the debug dylib

Real-world edge cases in static and dynamic linking, part 3 of 3

This is Part 3 of a three-part series:

The app builds. I press Run in Xcode, and it works. Then I launch it without Xcode and get:

Library not loaded: @rpath/XcodeFrameworkDynamic.framework/XcodeFrameworkDynamic

That was the symptom that sent me back to the binary. The app linked against the framework, so why couldn’t the loader find it?

Two details made the investigation confusing: Xcode could provide paths to build products at launch, and the Debug app contained a file named Library-linking-Test-Xcode-Framework.debug.dylib. They are related to the development workflow, but they solve different problems.

A build layout tells us where code lives. A launch environment can affect where dependencies are found. Keeping those questions separate makes this failure much easier to explain.

Three things to inspect separately

Dimension What to inspect What it can explain
Build layout ENABLE_DEBUG_DYLIB, actual files, symbols Why app code appears in a .debug.dylib
Packaging Final .app, copy/sign phases Whether a private dynamic framework travels with the app
Launch context Loaded image paths, relevant DYLD_* variables Why one launch can find a framework that another cannot

“Debug” and “Release” are configuration names. They usually select different optimization and layout settings, but the names themselves do not define loader behavior. A Release configuration launched from Xcode can still have a development launch environment. A CI job can build a Debug configuration.

The binary-layout checks below were repeated with Xcode 26.6 (17F113), Swift 6.3.3, and iOS Simulator builds. The earlier Xcode-versus-standalone launch observation is the motivation for the troubleshooting procedure; it is not a claim that every Xcode or Simulator version supplies identical environment variables.

What @rpath means

The app-code image records the framework’s install name:

@rpath/XcodeFrameworkDynamic.framework/XcodeFrameworkDynamic

@rpath is a placeholder for a run-path search. It is not a literal directory and does not mean “look everywhere in DerivedData.”

Prefix Meaning
@executable_path Directory containing the process’s main executable
@loader_path Directory containing the Mach-O image whose load command uses the prefix
@rpath Try the current run-path list, built from LC_RPATH entries along the dependency chain

For example, an iOS app can record this run path:

@executable_path/Frameworks

With the framework install name above, that gives a candidate inside the app:

MyApp.app/Frameworks/XcodeFrameworkDynamic.framework/XcodeFrameworkDynamic

An LC_RPATH entry supplies a place to search; it does not copy a missing framework there. See Apple’s dyld manual for the path substitutions and launch-environment overrides.

Pam and Dwight beside an @rpath reception desk with a directory on a stand and a doorway labeled Frameworks

A list of places to look is useful only if the required file exists at a reachable location.

A framework install name expanded using an app-relative run path, with separate checks for presence and compatibility

Inspect both the launcher and the app-code image

Use the APP, EXECUTABLE, and APP_CODE variables from Part 2, or set them here:

APP="/path/to/Library-linking-Test-Xcode-Framework.app"
EXECUTABLE=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleExecutable' "$APP/Info.plist")
APP_CODE="$APP/$EXECUTABLE"
if [ -f "$APP/$EXECUTABLE.debug.dylib" ]; then
    APP_CODE="$APP/$EXECUTABLE.debug.dylib"
fi

xcrun otool -arch arm64 -L "$APP/$EXECUTABLE"
xcrun otool -arch arm64 -L "$APP_CODE"
xcrun otool -arch arm64 -l "$APP/$EXECUTABLE" | grep -A2 LC_RPATH
xcrun otool -arch arm64 -l "$APP_CODE" | grep -A2 LC_RPATH

Replace the placeholder path with your build product. Do not stop after inspecting the launcher: the framework dependency may be recorded in the debug dylib.

In the inspected build, the app-code image has @executable_path/Frameworks among its run paths. That is a bundle-relative path. It is not an injected absolute path to a developer’s build directory.

How an Xcode launch can hide a missing embedded framework

Consider this deliberately incomplete product:

Build/Products/Debug-iphonesimulator/
├── XcodeFrameworkDynamic.framework/
│   └── XcodeFrameworkDynamic
└── MyApp.app/
    ├── MyApp
    └── MyApp.debug.dylib

The framework was built, but it was not copied into MyApp.app/Frameworks. The app can still link because the linker has access to the build products. That says nothing about a later standalone launch.

In a development launch, DYLD_FRAMEWORK_PATH can supply an additional directory containing the framework. If the process loads that external copy, the app appears to work despite its incomplete bundle. Outside that context, the same app may no longer find the dependency.

This does not require a different binary, a different configuration, or a .debug.dylib “rescue mechanism.” The decisive difference can be the available search paths and files.

Collect evidence in the running app

Pause the Xcode-launched app and inspect just the environment keys relevant to this question. Each command below is a single LLDB command:

(lldb) expression -l swift -- import Foundation
(lldb) expression -l swift -- ProcessInfo.processInfo.environment["DYLD_FRAMEWORK_PATH"]
(lldb) expression -l swift -- ProcessInfo.processInfo.environment["DYLD_LIBRARY_PATH"]
(lldb) image list -f XcodeFrameworkDynamic

An environment value only shows a possible search location. The loaded image path is the stronger evidence: did this process use the framework inside the app, or the copy beside it in build products?

If Swift expression evaluation is unavailable at that stop, inspect the scheme’s launch settings and enable a targeted dyld diagnostic, such as DYLD_PRINT_LIBRARIES=1, for a fresh run. Availability and treatment of DYLD_* variables depend on the platform and process restrictions; do not assume every launch honors them.

Avoid dumping the entire process environment into a public issue or article. It can contain unrelated credentials and local paths. Share only the relevant keys and replace personal path components.

Michael beside an empty tray in the App office and Dwight beside documents on a separate Build products table

The documents are available nearby, but they are still outside the app. A different launch context can expose that omission.

A controlled reproduction

Use the sample app, not a production target, for the missing-framework experiment:

  1. Keep the dynamic framework linked, but change its embedding option to Do Not Embed. Check that another copy phase is not still packaging it.
  2. Build into a fresh DerivedData directory. Confirm that the framework exists in build products and is absent from the resulting app.
  3. Run from Xcode. If it launches, inspect the relevant environment values and the loaded framework’s full path. If it fails here too, record that result; the development environment did not hide the omission.
  4. Stop the app and launch that same installed build from the Simulator home screen without rebuilding. Capture the loader error or loaded image path.
  5. Restore Embed & Sign, rebuild, inspect the bundle, and repeat the standalone launch.

Keep the configuration, Simulator runtime, and artifact fixed while comparing the two launch contexts. Switching Debug to Release at the same time changes several variables and weakens the diagnosis.

For a required launch-time dependency, a missing image can stop the process before the app reaches its entry point. A missing symbol, incompatible architecture, wrong platform slice, or invalid signature can produce a different loader failure. Read the full error, especially Referenced from and the attempted paths. Weak linking and libraries opened later with dlopen are separate cases.

A repeatable check with an explicit search path

I also checked the loader behavior on an isolated iPhone 16 Simulator running iOS 26.5, using the same Debug executable and debug dylib throughout. For the incomplete case, I removed the dynamic framework from a disposable copy of the built app, then installed that copy.

Installed bundle Additional framework search path Result
Framework embedded None supplied by the test Both math functions ran
Framework missing None supplied by the test Library not loaded; neither math function ran
The same incomplete bundle Build products directory supplied explicitly Both math functions ran

The app-code file’s SHA-256 was identical across these cases. The successful processes remained running until the test stopped them; this was a launch check, not a performance benchmark.

For the third case, simctl can pass the override to the launched process:

SIMCTL_CHILD_DYLD_FRAMEWORK_PATH="$BUILD_PRODUCTS" \
  xcrun simctl launch --terminate-running-process "$SIMULATOR_UDID" "$BUNDLE_ID"

Set the three variables to your build-products directory, test Simulator identifier, and app bundle identifier. Install the test app first. The SIMCTL_CHILD_ prefix is how this command supplies DYLD_FRAMEWORK_PATH to the child process.

This checks the effect of an explicit search path. It does not establish which variables a particular Xcode scheme supplies automatically; inspect that launch separately using the earlier steps. Keep the experiment on a disposable Simulator build, and restore normal embedding afterward.

What App.debug.dylib actually contains

In Xcode’s debug dylib layout, the executable is a small entry point and the app’s linked code lives in a companion dynamic library. This supports the shared build product used by normal runs and Previews.

Apple documents the default conditions for ENABLE_DEBUG_DYLIB: a bundled executable target, SWIFT_VERSION set, and SWIFT_OPTIMIZATION_LEVEL=-Onone. The setting is target-specific; it is not a universal property of every Debug build. See Understanding build product layout changes in Xcode.

A .debug.dylib contains executable code. It is not simply a bag of debug symbols, and it is not interchangeable with a .dSYM.

Here is the layout of the sample with debug dylib support enabled:

MyApp.app/
├── MyApp                              small launcher
├── MyApp.debug.dylib                  app code + linked static library code
└── Frameworks/
    └── XcodeFrameworkDynamic.framework/
        └── XcodeFrameworkDynamic     separate dynamic implementation

With that support disabled, the app and static library code can instead live in MyApp:

MyApp.app/
├── MyApp                              app code + linked static library code
└── Frameworks/
    └── XcodeFrameworkDynamic.framework/
        └── XcodeFrameworkDynamic     still a separate implementation

The same static code linked into a debug dylib or main executable, while the dynamic framework remains a separate image in both layouts

The static library remains statically linked in both layouts. The output image changed; the library did not become a separately loaded framework.

A small App reception desk leading to an office labeled App.debug.dylib

The entrance is small; the work happens in the other room. Statically linked code can live in that room too.

Verify the layout instead of guessing from the configuration name

For the sample project, inspect its effective settings:

xcodebuild \
  -project Library-linking-Test-Xcode-Framework.xcodeproj \
  -scheme Debug \
  -configuration Debug \
  -sdk iphonesimulator \
  -showBuildSettings \
  | grep -E 'ENABLE_DEBUG_DYLIB|SWIFT_OPTIMIZATION_LEVEL|LD_RUNPATH_SEARCH_PATHS'

The command can print settings for more than one target. Check the app target’s section when interpreting them. Replace the project and scheme names for your own app.

For a controlled comparison, build the app with its usual settings, then build again with ENABLE_DEBUG_DYLIB=NO. Use separate output directories so an old dylib cannot confuse the result. This changes layout; it does not fix a missing embedded framework.

The three sample builds inspected during this revision produced:

Build Image containing the static MyMathStatic.add definition Dynamic dependency
Debug, default layout App.debug.dylib Separate framework
Debug, ENABLE_DEBUG_DYLIB=NO App Separate framework
Release, sample defaults App Separate framework

These are results for this project and toolchain, not rules inferred from the words “Debug” and “Release.”

Why this matters for CI and distribution

A CI build completing successfully proves that the build completed. An archive completing successfully proves that an archive was created. Neither result alone proves that every shipped process will load every required private framework.

For an iOS app, inspect the actual artifact you intend to distribute:

  1. Locate the app under Products/Applications in the archive, or under Payload in an extracted IPA.
  2. Inspect the executable’s recorded dependencies and run paths. Repeat for embedded dynamic frameworks and app extensions, including their transitive dependencies.
  3. Confirm that required private dynamic frameworks are packaged at reachable locations with the correct device platform, architecture, and signing. System frameworks are supplied by the OS.
  4. Launch the exported app through the appropriate device distribution route, without relying on Xcode’s build-products directory. Exercise extension entry points too.

Do not “fix” distribution by adding an absolute path to your local build directory. That directory will not exist on a user’s device. Fix the dependency graph, copying/signing configuration, or the relative run paths in the product.

Apple’s framework embedding troubleshooting guide is useful for missing, incompatible, and incorrectly packaged framework errors. Its older UI screenshots should be read alongside the build phases in your current Xcode version.

Does choosing static linking avoid this problem?

It removes one specific requirement: there is no separate runtime file for that static archive that dyld must find. It does not remove the app’s other dynamic dependencies or copy its resources automatically.

For this series, I would use the following diagnostic order:

  • Where is the implementation? Find its owning image.
  • What does that image require? Read the load commands.
  • What did we ship? Inspect the final bundle.
  • What actually loaded? Check the process and its launch context.

That sequence explains both the direct-versus-stub call in Part 2 and the app that works only from Xcode. It also gives us something more useful than “Debug is forgiving”: a specific file, dependency, or path to correct.

Last updated on

Discussion

Loading discussion…

On this page