This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Kawa and System.loadLibrary and native code
- From: "Sudarshan S Chawathe" <chaw at eip10 dot org>
- To: Kawa mailing list <kawa at sourceware dot org>
- Date: Sun, 12 May 2019 11:24:08 -0400
- Subject: Kawa and System.loadLibrary and native code
- Reply-to: "Sudarshan S Chawathe" <chaw at eip10 dot org>
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