Closed Ben-Mack closed 3 years ago
Theoretically, yes: https://doc.rust-lang.org/nomicon/ffi.html#calling-rust-code-from-c
Rust can make C-compatible static libraries and export C ABI structs and functions, which you can then pick up on the C++ side. There's even tooling like https://lib.rs/cxx that automates a lot of this.
However, I haven't prepared an interface for it, so it needs a bit of DIY. If you'd like to do it, then:
dssim-core
is the library interface with minimal dependencies (no image I/O) so it's the best one to expose. https://github.com/kornelski/dssim/tree/main/dssim-core#[no_mangle] pub extern "C" fn
type for the functionality you need.[lib]\ncrate-type = ["lib", "staticlib"]
to https://github.com/kornelski/dssim/blob/main/dssim-core/Cargo.toml cargo build --release
will then make target/release/libdssim-core.a
that you can link with a C or C++ projectThank you for the quick and detailed response!
Please consider adding such interface to the library as I think there'll be more demand to use this lib with C/C++.
Done in b5c4195f2779cac60888bc0f8a5dba9a65b0a5fe
Wow, that's really quick, these code comments are so detailed too, thanks a lot!
I have no experience with Rust so it would be great if there's some guidance on how to intergrate dssim v2 with c++ codebase.