How would you use a dll/dylib/so file that is generated by Rust inside Rust. While searching other sites all i find is them using stuff like extern "c" but the problem here is that im using Rust. Does anyone know how to do it?
Are you trying to use another crate as a dependency, or is this specifically about a library which exposes a C API that other languages can link to?
If it's the former then there is a section of The Rust Programming Language which walks you through adding a dependency to your crate:
Under the hood this will ask
cargo to tell
rustc to link to the corresponding
*.rlib file (essentially an object file with some Rust-specific metadata).
If it is the latter then you'll need to write a build script that tells
rustc how it can locate the DLL. This is typically never done for Rust-to-Rust dependencies because adding it to your
Cargo.toml is so much more convenient and means you aren't constrained to a C API.
I am trying to use my own crate which i made in rust but compiled to a dll. I'm trying to make my on game engine and having the game engine as a dependency every time you create a new project would be way to massive. But if you had a dll file you can share it through multiple projects.
Game engine -> dll
and the dll is used in a rust project.
Compilation to a DLL is mostly supported so that you can expose Rust libraries to systems in other languages, and isn’t really designed for sharing a single Rust dependency between multiple projects. That use case is not well addressed in Rust today, although there are some efforts towards having a full shared library system designed for Rust, and the idiomatic way to do what you’re doing would be through Cargo.
Cargo is smarter than you expect and generally won’t download multiple copies of the same dependency if it doesn’t have to, though. It will link it multiple times, so the final binaries will include a copy of your engine for each program you use it in, but you might find it’s not as intolerable or as disk space intensive as you fear.
the problem here is not cargo. Lets say someone is using your game engine. and they create a project with the game engine as a dependency. Now if they are working on another project you will have the game engine as a dependency. Having a dll prevents that by sharing the same in multiple projects and adding it in when you compile.
Not sure how relevant it is here but some people have devised solutions for this scenario.
Here is some google output.