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

Cannot execute Hello World on macOS with prefer-dynamic #50001

Closed
kenorb opened this issue Apr 16, 2018 · 1 comment
Closed

Cannot execute Hello World on macOS with prefer-dynamic #50001

kenorb opened this issue Apr 16, 2018 · 1 comment
Labels
-Cprefer-dynamic Codegen option: Prefer dynamic linking to static linking. A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. O-macos Operating system: macOS T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kenorb
Copy link

kenorb commented Apr 16, 2018

I've installed Rust compiler via brew install rust and I have the following Hello World program:

fn main() {
    println!("Hello World!");
}

I've compiled it via: rustc -Cprefer-dynamic hello.rs for a smaller size.

However I've got the following error when executing it:

$ ./hello 
dyld: Library not loaded: @rpath/libstd-99517fd8418575af.dylib
  Referenced from: mydir/./hello
  Reason: image not found
Abort trap: 6

Here is the output from otool:

$ otool -L hello
hello:
	@rpath/libstd-99517fd8418575af.dylib (compatibility version 0.0.0, current version 0.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.0.0)
	/usr/lib/libresolv.9.dylib (compatibility version 1.0.0, current version 1.0.0)

What I am missing?

@XAMPPRocky XAMPPRocky added O-macos Operating system: macOS T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. A-linkage Area: linking into static, shared libraries and binaries labels Aug 27, 2018
@workingjubilee workingjubilee added the -Cprefer-dynamic Codegen option: Prefer dynamic linking to static linking. label Apr 6, 2024
@bjorn3
Copy link
Member

bjorn3 commented Nov 28, 2024

If you use dynamic linking, you need to tell the dynamic linker where to find the dynamic libraries if they are not installed globally on the system. On macOS this would be using the DYLD_LIBRARY_PATH env var, on other Unixes the LD_LIBRARY_PATH env var and on Windows the PATH env var.

@bjorn3 bjorn3 closed this as completed Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-Cprefer-dynamic Codegen option: Prefer dynamic linking to static linking. A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. O-macos Operating system: macOS T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants