I tried to call an existing native method, but get UnsatisfiedLinkError, and do not understand why since I copied existing code from the JDK and didn't wrote my own C function.
I copied some code from the JDK Sockets Java source code. Running on Ubuntu.
public class Sokket {
static {
System.loadLibrary ("net");
}
static {
initProto ();
}
// rest ommited for brevity
}
Running this code results in:
Exception in thread "main" java.lang.UnsatisfiedLinkError:
be.good.Sokket.initProto()V
at be.good.Sokket.initProto(Native Method)
at be.good.Sokket.<clinit>(Sokket.java:12)
I tried other native methods but same error, I changed the name of "net" to test if the library can be found and then I do get an error that that lib cannot be found in the java.library.path
, I changed the name of "initProto" to test if the method can be found and then i do get the same error. So it looks to me that the "libnet.so" in the JDK lib directory has no initProto() but also no createSocket()
.
When I run with -verbose:jni
I do see a lot of libs loaded but no reference to "net" or "initProto".
How can I call existing native methods from my own code?