-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Deficient documentation for linking external .dylib on macos #4421
Comments
I think the build script is the problem here because the string literal you're passing to |
Still doesn't work. This is what I tried:
|
That's the same, you need to remove the newline and leading whitespace or use two |
same error |
in my case, it seems that if i have both |
@za121 is |
At the time of your reply, /path/to/lib was outside of the build directory. I'm curious what I should do to manage that path by the application, but just to see what would happen, I moved the dylib to be inside the same folder hierarchy as the cargo project (/foobar/path/to/lib where main.rs is located at /foobar/src/main.rs), but it didn't fix the problem. |
The "build directory" in this case is the |
|
I fought this issue and in my case I needed to add in the
dynlib in At this point I was able to compile. Then I got runtime errors: And now I have no errors. I tried all the environment parameters, RUSTFLAGS, nothing worked.. |
This is what we have right now:
http://doc.crates.io/build-script.html
Here's what Mac users go through to link .dylib libraries (still didn't work for me, but closer):
https://stackoverflow.com/questions/40602708/linking-rust-application-with-a-dynamic-library-not-in-the-runtime-linker-search
I haven't been able to find documentation for an FFI "hello world" using a dylib. Here's what my current (bad) flow has been trying to work through this problem.
0.) cargo new foobar --bin
1.) Alright, I'll use a build script to link against /path/to/lib/libfoo.1.dylib
build.rs
2.) Alright, well after an online search, I've learned that in [profile.dev] that rpath defaults to false for some reason, even on Mac. No big deal though, I'll just set it to true
Cargo.toml
Exactly the same error. Note that at this point, I haven't even tried to call any library functions from the library, just link it. I've still got cargo's basic hello world in main.rs
3. ) I stumble across the stack overflow question/answer linked at the top of this post and I see this line:
cargo rustc -- -C link-args="-Wl,-rpath,/scratch/library/"
I'm not really sure exactly what it does, I can't really figure out how it works from looking at it, and a search for cargo rustc isn't too helpful, so I paste it into the commandline, changing the /scratch/library/ to /path/to/lib/ and then try
cargo run
again, but get the same error.4.) Ah, maybe I need to add that cargo line to the build.rs script? The build.rs main function now looks like this:
Nope, no dice. At this point, things are working for the stackoverflow question answerer, but I'm still stuck with my binary missing the rpath entry for my library and unable to run on my chosen platform. So in the end, this issue is both a question (how do I make this work on macos?) and a documentation request (linking against an arbitrary c dylib is undoubtedly pretty common especially among c developers who want to incrementally try out Rust but can't just rewrite their whole code base first).
The text was updated successfully, but these errors were encountered: