Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling C++ from clojure

Tags:

c++

clojure

Is it possible to call C++ libraries like CGAL or VTK from Clojure? Can this be possibly done if C++ functions are wrapped with C interface functions, like Haskell does with the c2hs tool and its excellent C FFI?

Can I call clojure code from C++? this question asks for the reverse,

like image 327
smilingbuddha Avatar asked Nov 18 '18 08:11

smilingbuddha


1 Answers

You have several alternatives here:

  • you can do it the same way as Java does - via JNI (Java Native Interface). There is a complete example of using clojure with JNI.
  • there is a JNA project that allows to have access to native libraries without writing bridge as JNI requires. There is an old (2009th) blog post about using JNA with Clojure.
  • for C++ better alternative could be JavaCpp.
  • generate Java bindings via Swig & access them as normal Java methods.
like image 193
Alex Ott Avatar answered Oct 04 '22 18:10

Alex Ott