Giter Site home page Giter Site logo

Can v2 be used in c++? about dssim HOT 4 CLOSED

kornelski avatar kornelski commented on August 20, 2024
Can v2 be used in c++?

from dssim.

Comments (4)

kornelski avatar kornelski commented on August 20, 2024 1

Done in b5c4195

from dssim.

kornelski avatar kornelski commented on August 20, 2024

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:

  1. 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
  2. Create C-compatible functions that have #[no_mangle] pub extern "C" fn type for the functionality you need.
  3. Write their equivalent as a C header (or use https://lib.rs/cbindgen to automate this)
  4. Add [lib]\ncrate-type = ["lib", "staticlib"] to https://github.com/kornelski/dssim/blob/main/dssim-core/Cargo.toml
  5. cargo build --release will then make target/release/libdssim-core.a that you can link with a C or C++ project

from dssim.

Ben-Mack avatar Ben-Mack commented on August 20, 2024

Thank 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++.

from dssim.

Ben-Mack avatar Ben-Mack commented on August 20, 2024

Wow, that's really quick, these code comments are so detailed too, thanks a lot!

from dssim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.