System/loadLibrary uses the paths set in the System property java.library.path to look for dynamic libraries so you need to make sure it contains the directory where your .so is. I think it also gets cached at first read or something stupid like that so it's very important to get java.library.path right before the first time you call System/loadLibrary. The syntax for java.library.path is the same as for classpath (wich is the same as for the OS path env. variable). You also have to make sure not to call System/loadLibrary from the top level of a file unless you are just playing with the repl. You need to call it from inside a function or everything will break if you try to pre compile the code since the library will be linked at compile time only and not at runtime... So to make sure it's linked at runtime, never put System/loadLibrary on the top level.
To set java.library.path from the command line use the parameter - Djava.library.path='your stuff here'. To set it from Clojure code: (System/setProperty "java.library.path" "your stuff here") /Markus On Nov 4, 11:42 pm, Seth <wbu...@gmail.com> wrote: > Ive recently had troubles using swig in clojure getting a 'unsatisfied > link exception' even though using the swig generated library worked in > regular java code. I believe there was a post on this somewhere in > these google groups. > > Anyways, I have figured out that if I place the following code in a > clojure file (test.clj) > (System/loadLibrary "Seth") > > and go (compile 'test) on the REPL, i get > > No such file or directory > [Thrown class java.io.IOException] > > Restarts: > 0: [QUIT] Quit to the SLIME top level > > Backtrace: > 0: java.io.UnixFileSystem.createFileExclusively(Native Method) > 1: java.io.File.createNewFile(File.java:900) > 2: clojure.lang.Compiler.writeClassFile(Compiler.java:5885) > 3: clojure.lang.Compiler.compile(Compiler.java:6043) > 4: clojure.lang.RT.compile(RT.java:368) > 5: clojure.lang.RT.load(RT.java:407) > 6: clojure.lang.RT.load(RT.java:381) > 7: clojure.core$load$fn__4511.invoke(core.clj:4905) > 8: clojure.core$load.doInvoke(core.clj:4904) > 9: clojure.lang.RestFn.invoke(RestFn.java:409) > --more-- > > However, afterwards i can succesfully do > (import Seth) > (Seth/add 2 3) => 5 > > I cant do the loadlibrary thing on the repl, or it wont work (i get > the 'unsatisfied link error' when calling (Seth/add)). Notice that if > I do (compile 'test) again i get the same error above, which is > weird because if i do (System/loadLibrary "Seth") on the repl i get > the 'expected' error > > Native Library /home/seth/.random/java/libSeth.so already loaded in > another classloader > [Thrown class java.lang.UnsatisfiedLinkError] > > Restarts: > 0: [QUIT] Quit to the SLIME top level > > Backtrace: > 0: java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1715) > 1: java.lang.ClassLoader.loadLibrary(ClassLoader.java:1675) > 2: java.lang.Runtime.loadLibrary0(Runtime.java:840) > 3: java.lang.System.loadLibrary(System.java:1047) > 4: user$eval1825.invoke(NO_SOURCE_FILE:1) > 5: clojure.lang.Compiler.eval(Compiler.java:5424) > 6: clojure.lang.Compiler.eval(Compiler.java:5391) > 7: clojure.core$eval.invoke(core.clj:2382) > --more-- > > Anyone know whats going on and how this can be fixed? -- 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