Crate_type=rlib,dylib and ldd.exe std-*.dll not found

Hello,
i probe around dynamic linking in rust and with the rust abi.

So i use exactly this project and build it
to avoid cargo errors i have to use

crate-type = ["rlib","dylib"]
i use this RUSTFLAGS=-C prefer-dynamic
lto=false
cargo build --release
and the the compile process runs trough with an binary and dlls
but when i use ldd.exe .\targets\release\binary.exe

dy_libs.rs => **** found
std-8984bea53711d8dc.dll => not found

What is my failure? I want a normal binary that only dynamical links to dy_lib.rs and have the std-lib static.
I want that but without the std not found error???
thx

If you create a rust dylib, it will always dynamically link libstd. Or to be precise if you don't pass -Cprefer-dynamic to dynamically link libstd there is no way to use the resulting dylib as dependency without rustc erroring. A cdylib will statically link libstd just fine, but can only be used the same way C dynamic libraries are used. (through the C abi, not as rust crate)

I'm not an expert on this, but I believe the reason this is impossible is that on Windows, libraries cannot link to symbols contained in the executable.

This is a problem because it means binary.exe and dy_libs.dll would both have their own, independent copy of the standard library. This would include all their global state, which can cause problems if (as an invented example) you pass a File value created by one copy of std to a function in the other copy. I don't know of any specific problems with this because, as you've noticed, the compiler won't let you do it in the first place.

@bjorn3 @DanielKeep
Thx for that clearness. I think in the future this is questions that other new users hopefully ask:).
Then i must every changelog, from stable or nightly, read more hopefully that Rust became an ABI like C. An stable api. CrateType dylib is a starting to that hope:).

I guess since asking about dylib is a bit annoying I will ask a question about the savepath/dllnaming again.

BTW:something funny on the side: Why i have do all binary-size-optimations, especially panic path optimization:), the exe don't shows an classical win32-api "no dll" error;).

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.