Fork me on GitHub
#interop
<
2022-07-12
>
mpdairy02:07:18

I'm trying to use the JNI to call Clojure from C. There are a few stackoverflow answers that show how to do it, but for some reason I cannot load the clojure.java.api.Clojure class. This:

clojure    = (*env)->FindClass(env, "clojure/java/api/Clojure");
returns a NULL pointer. That by itself would suggest a clojure jar loading problem, but I can load the IFn class with this just fine:
ifn        = (*env)->FindClass(env, "clojure/lang/IFn");
That returns a non-NULL pointer. I've tried it with the most recent version of clojure and the openjdk, as well as with older versions that are in the SO answers. Maybe something weird is going on with Clojure's classloader interfering?

Alex Miller (Clojure team)03:07:48

I can't see why those would be any different

mpdairy17:07:49

Oh, there's a way to print out Java exceptions from the JNI:

Caused by: java.io.FileNotFoundException: Could not locate clojure/spec/alpha__init.class, clojure/spec/alpha.clj or clojure/spec/alpha.cljc on classpath.
Looks like clojure.java.api.Clojure requires spec for some reason, so I'll just have to include the spec jar and it should work. Or maybe there's a way to load it without requiring spec?

Alex Miller (Clojure team)17:07:44

it is possible to pass the jvm flag -Dclojure.spec.skip-macros=true but otherwise yes