Kawa and System.loadLibrary and native code

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Kawa and System.loadLibrary and native code

Sudarshan S Chawathe
I am trying to use OpenCV from Kawa using the OpenCV-Java library (which
uses JNI) but cannot seem to get rid of an UnsatisfiedLinkError.  I
suspect I am confused about how System.loadLibrary works relative to
class loading in Kawa (or Java for that matter) and would be grateful
for any pointers.

Here is my test code:


  (import (class org.opencv.core
            Core CvType Mat))

  (define (hello)
    (java.lang.System:loadLibrary Core:NATIVE_LIBRARY_NAME)
    (display ((Mat:eye 3 3 CvType:CV_8UC1):dump))
    (newline))

  (hello)


Core:NATIVE_LIBRARY_Name evaluates to "opencv_java249" on my setup
(Debian 9) and I am invoking kawa with the following command line
(/usr/lib/jni contains libopencv_java249.so):

  java -Djava.library.path="/usr/lib/jni:" kawa.repl \
  --output-format readable-scheme $*


Here's the error trace:

  Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_eye(III)J
          at org.opencv.core.Mat.n_eye(Native Method)
          at org.opencv.core.Mat.eye(Mat.java:1467)
          at atInteractiveLevel-4.hello(tty:17)
          at atInteractiveLevel-4.hello$check(tty:15)
          at gnu.mapping.Procedure.applyToConsumerDefault(Procedure.java:75)
          at gnu.mapping.CallContext.runUntilDone(CallContext.java:586)
          at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:343)
          at gnu.expr.ModuleExp.evalModule(ModuleExp.java:211)
          at kawa.Shell.run(Shell.java:289)
          at kawa.Shell.run(Shell.java:196)
          at kawa.Shell.run(Shell.java:183)
          at kawa.repl.processArgs(repl.java:724)
          at kawa.repl.main(repl.java:830)

For reference, here is the Java version, from the opencv-java tutorial,
which works fine.  If I comment out the System.loadlibrary line then it
generates an error very similar to what I get from the above Kawa code.

  import org.opencv.core.Core;
  import org.opencv.core.CvType;
  import org.opencv.core.Mat;

  public class HelloCV {
      public static void main(String[] args){
          System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
          Mat mat = Mat.eye(3, 3, CvType.CV_8UC1);
          System.out.println("mat = " + mat.dump());
      }
  }


Regards,

-chaw