nagisa / rust_libloading

Bindings around the platform's dynamic library loading primitives with greatly improved memory safety.

Home Page:https://docs.rs/libloading

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Worth mentioning somewhere that dynamically loadable rust crate has to be cdylib?

fulara opened this issue · comments

Just spent some time investigating why my rust dll wont load, turned out that I mistakenly put dylib as crate-type instead of cdylib

so inside Cargo.toml of library I had:

crate-type=["dylib", "rlib"]

In order for a library to be loadable this should have been:

crate-type=["cdylib", "rlib"]

Error that I was getting On windows:

Os { code: 126, kind: Other, message: "The specified module could not be found." }'
println!("result is: {:?}", libloading::Library::new(dll_path.clone()));

If readme wont be updated, this issue should serve enough as enough of a documentation.
Similar issue in rust-lang: rust-lang-issue

Difference between dylib and cdylib can be found on rust documentation here, as a summary:

cdylib - A dynamic system library will be produced
dylib - A dynamic Rust library will be produced.

Very technically it is possible to load either kind of library, it is just the case that loading dylib is more involved.

I don’t really see a good place to fit this sort of advice either as this crate is meant to load all sorts of shared libraries, not just those implemented in Rust.

Given those points I think keeping this documented as an issue is good enough.