@5 is sort of correct.
To make a function export itself in rust, add the following before it:
This prevents Name mangling.
Additionally, remember the difference between dylib, staticlib, and cdylib:
--crate-type=dylib, #[crate_type = "dylib"] - A dynamic Rust library will be produced. This is different from the lib output type in that this forces dynamic library generation. The resulting dynamic library can be used as a dependency for other libraries and/or executables. This output type will create *.so files on linux, *.dylib files on osx, and *.dll files on windows.
--crate-type=staticlib, #[crate_type = "staticlib"] - A static system library will be produced. This is different from other library outputs in that the compiler will never attempt to link to staticlib outputs. The purpose of this output type is to create a static library containing all of the local crate's code along with all upstream dependencies. The static library is actually a *.a archive on linux and osx and a *.lib file on windows. This format is recommended for use in situations such as linking Rust code into an existing non-Rust application because it will not have dynamic dependencies on other Rust code.
--crate-type=cdylib, #[crate_type = "cdylib"] - A dynamic system library will be produced. This is used when compiling a dynamic library to be loaded from another language. This output type will create *.so files on Linux, *.dylib files on macOS, and *.dll files on Windows.
So, in summary:
If you want a rust library DLL (which is compiler-defined), use crate-type = ["dylib"].
If you want something that can be called from another language, use crate-type - ["cdylib"]
If you want a static library, use crate-type = ["staticlib"]
Finally, in your DLL, either add:
before your function, or:
pub extern "C"
If you want structures/enumerations/... visible in your DLL, add:
Before the struct/enum/... in question.
Just a question... why are you doing this -- do you know the language sufficiently enough for this to be useful to you?
"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.