I have a Rust project that I want to embed in another application as a dylib. I have crate_type = ["dylib"] set in my Cargo.toml, but I'm not sure if this should be cdylib instead.
When I build the project, it produces a libfoo.dylib in target/debug as expected, but looking at otool -L it also links against a libfoo.dylib in target/debug/deps/. If I'm going to be using this in another application, will I have to provide both dylibs?
Also, when the crate type is cdylib, it'll produce two dylibs as well but the one in deps will have a hash tacked onto the end of the filename. I'm not sure what the difference between these two crate types are.
I can avoid getting two dylibs by using just rustc, however I'd like to use cargo. What is the recommended way of going about embedding Rust as a dylib in other applications?
I'm using Rust on macOS 10.12 if that's significant
After a bit more research, it turns out cdylib statically links the Rust dependencies, and dylib is for dynamic linking with other Rust projects.
As for embedding, everything I found suggests that statically linking the Rust library is the recommended way. For using the Rust library dynamically, setting rpath = true in my [profile] section solved the issues with redundant dylibs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With