This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-29
Channels
- # announcements (6)
- # babashka (23)
- # beginners (15)
- # biff (15)
- # calva (17)
- # clara (5)
- # clj-kondo (41)
- # cljdoc (2)
- # cljs-dev (67)
- # cljsrn (18)
- # clojure (19)
- # clojure-europe (25)
- # clojure-nl (2)
- # clojure-norway (9)
- # clojure-uk (2)
- # clojurescript (26)
- # core-typed (6)
- # cursive (15)
- # data-science (30)
- # datahike (1)
- # datomic (18)
- # docker (6)
- # emacs (10)
- # events (2)
- # graalvm (15)
- # graphql (5)
- # hugsql (4)
- # jobs-discuss (1)
- # joker (7)
- # lsp (36)
- # malli (28)
- # off-topic (46)
- # other-languages (1)
- # pathom (5)
- # pedestal (6)
- # polylith (5)
- # reitit (2)
- # releases (1)
- # rewrite-clj (63)
- # shadow-cljs (7)
- # spacemacs (16)
- # squint (6)
- # tools-deps (6)
- # xtdb (13)
Hi everyone. Im using native-image to build an executable of a clojure codebase that links with C code. It all works great by building the C as a *.a file and linking it in at compile time during native-image. But running the project under graals java, how do I consume the C library then?
I can compile it as a *.so, but if I loadLibrary it when I call the C code I get an UnsatisfiedLink error.
If I add JNI to the C library, and then compile it as a .so, and then loadLibrary it, then it does load and work (including the substrate C interop calls)
it will be slow and annoying to develop when every change requires a full native-image
(examining the symbols in the JNI .so there is a JvRegisterClasses call that is not present in the plain .so file. I think this has the magic that makes loadLibrary link it correctly)
it's been loooooong time since I touched C etc - does graal / jni support similar mechanism to LD_LIBRARY_PATH
? That's how dynamic linking works in other languages/runtimes
it does. thats all set up. the loadLibrary of the vanilla code loads... it just then doesnt work when called
I think you need to do JNI in the JVM still so you have to maintain two versions of the FFI code
yeah thats what I thought too. Just hoping someone with more experience shows me a magical graal blessed way that I dont know about 🙂
have to go sleep now. But will check back in the morning if anyone has any better solutions.
I've started writing all my ffi code using dtype-next's ffi since you can define the interface once and use it in a number of contexts. I'm not sure it covers the exact contexts you've listed, but I think it does. If it doesn't, the ffi interface is extensible. https://github.com/cnuernber/dtype-next/tree/master/examples/clj-ffi
@U7RJTCH6J that looks really great! I will give that a go. Thanks for the pointer.