Skip to content

dylib not found when running without "cargo run" on macOS Sonoma #141

Open
@aclysma

Description

It looks like macOS Sonoma no longer searches /usr/local/lib by default as a fallback https://developer.apple.com/forums/thread/737920

Setting DYLD_PRINT_SEARCHING=1 shows dylib resolution

Prior to macOS Sonoma when running my compiled binary directly:

dyld[23515]: find path "@rpath/libshaderc_shared.1.dylib"
dyld[23515]:   possible path(default fallback): "/usr/local/lib/libshaderc_shared.1.dylib"
dyld[23515]:   found: dylib-from-disk: "/usr/local/lib/libshaderc_shared.1.dylib"

On macOS Sonoma if using cargo run to start my program:

dyld[8143]: find path "@rpath/libshaderc_shared.1.dylib"
dyld[8143]:   possible path(DYLD_FRAMEWORK/LIBRARY_FALLBACK_PATH): "<<PROJECT_ROOT>>/target/debug/build/basis-universal-sys-ca27b139e15249c2/out/libshaderc_shared.1.dylib"
...
dyld[8143]: no pseudo-dylibs to search
dyld[8143]:   possible path(DYLD_FRAMEWORK/LIBRARY_FALLBACK_PATH): "/usr/local/lib/libshaderc_shared.1.dylib"
dyld[8143]: no pseudo-dylibs to search
dyld[8143]:   found: dylib-from-disk: "/usr/local/lib/libshaderc_shared.1.dylib"

Note that the path is being set by cargo run https://doc.rust-lang.org/cargo/reference/environment-variables.html#dynamic-library-paths

However, on macOS Sonoma when running my compiled binary directly (not via cargo run)

dyld[8135]: find path "@rpath/libshaderc_shared.1.dylib"
dyld[8135]:   not found: "@rpath/libshaderc_shared.1.dylib"

Adding this in .cargo/config.toml allows the binary to resolve the dylib

[target.aarch64-apple-darwin]
rustflags = ["-C", "link-arg=-Wl,-rpath,/usr/local/lib"]

Unfortunately I'm not sure what the best way forward would be here. Ideally linker flags would not need to be manually added to the project, but on the other hand it's odd to me that a direct path to the install location of the dylib should be specified at build time.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions