I’m trying to understand what the difference between
cdylib are. I want to understand better how to work dynamic linking in Rust. I wrote a tutorial with a minimal example of how to do plugins in Rust, using
dylib, but I’ve also seen a comment on GitHub about
dylib being a world of pain right now.
I understand that using
dylib would require using the same exact version of the rust compiler and that isn’t a concern for me, but I’ve seen a cargo issue that that brings up the issue that Cargo is not going to build the dependencies of a library that I build as
dylib which would mean that I need to manually compile all of the dependencies, which could result in linking issues, so it wouldn’t actually solve the problem anyway.
cdylib is supposed to be a decent enough solution, as far as I can tell, but the size of
cdylib's are much larger than their equivalent
dylib when I test that with my minimal example codebase. This makes me think that the
cdylib is bundling more code into the library and possibly statically linking dependencies like the standard library, which sort of defeats the purpose of using the
dylib which is supposed to avoid bundling dependencies into every plugin.
Also, on a side note, it looks like the
rpath Rust codegen option also doesn’t work with
In summary, I’m trying to understand the differences in behavior when I change the crate type from
cdylib in my example. What is the cause of the following differences:
cdyliblibraries are much larger than the
dyliblibraries. 1.5-1.8M compared to 14kb-500kb in my example.
-C rpathrust flag doesn’t cause the
cdylibs to be loaded relative to the binary’s path.
- What is the difference in how the dependencies of a
dylibare bundled/linked, including how the standard library is linked?