2019-08-03 07:48:42

so, i started learning Rust about a weak ago, i have made an experimental dll, would there be any way for me to use this dll inside of my main rust executable? i googled it but found nothing on the subject, this is why i posted this topic, thanks for any help given to me

2019-08-03 15:16:18

If both units of code are in Rust, it'd be far better for one to just depend on another. If you're really compiling something into a DLL, you're likely exporting a C-compatible interface, and it doesn't make sense to have Rust code interact with other Rust code over that. And Rust's FFI is kind of a pain, and something you may not want to interact with during your first week with Rust. Hell, I'm learning it this week after *years* with Rust, and it's not been fun. smile

2019-08-03 17:08:39

I'm not sure you need to compile it into a DLL in order to use it.
More likely, you can just include it, into the main program. I'm not sure what the syntax is, but it'd probably be something like "module code" assuming you had a file called code.rs in your src directory.
Then you compile, it'll get compiled too.

2019-08-03 17:19:42

Same as 3, I don't think you have to make it a dll, just include it.

2019-08-03 19:36:18

If its written in rust, and your project is in rust, then using FFI with that is useless (unless your trying to make a module/plug-in system). If its not, though, then its a bit trickier, and involves a bit more work. Start with the libloading crate though if your interested. (Passing structs ad such is hard, though, I still can't really figure that out. Heh.)

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github