System.loadLibrary in java has counter-intuitive behaviour. It examines the
stack to figure out what class invoked it, then loads the native library
into the Classloader of that class. At the REPL, this classloader is
usually a transient instance of DynamicClassLoader, which isn't very
helpful in terms of actually having access to the library once it's been
loaded.

This is why the function clojure.lang.RT/loadLibrary exists. Since RT is
loaded by clojure's parent classloader, any libraries loaded using that
method end up in the correct place.

TLDR: use (clojure.lang.RT/loadLibrary ...) instead of
(java.lang.System/loadLibrary ...)

--Aaron



On Tue, May 13, 2014 at 3:00 PM, Gary Verhaegen <gary.verhae...@gmail.com>wrote:

> Hi everyone,
>
> I have recently been working on something [0] that required (consisted
> mainly of, really) loading native dlls. I have encountered a
> surprising (to me) behaviour: calling (System/load path) from Clojure
> correctly loaded the library, but did not link the JNI methods,
> whereas just switching to Java did link everything correctly.
>
> I spent more time on this than I care to admit, but in the end what
> worked was creating a Java class with a single static method that
> called System.load [1] and calling that from Clojure [2].
>
> So my question is: is that somehow expected behaviour, or should I
> file a bug report (after I investigate a bit more so I can provide
> more details)?
>
>
> [0] https://github.com/gaverhae/naughtmq
> [1]
> https://github.com/gaverhae/naughtmq/blob/master/src/naughtmq/PrivateLoader.java
> [2]
> https://github.com/gaverhae/naughtmq/blob/master/src/naughtmq/core.clj#L89
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to