Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aclysma opened this issue Nov 11, 2023 · 0 comments
Open

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

aclysma opened this issue Nov 11, 2023 · 0 comments

Comments

@aclysma
Copy link

aclysma commented Nov 11, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant