Skip to content

Why am I getting this UnsatisfiedLinkError with native code?

I have a library called HelloWorld.so and a program HelloWorld.java with this content:

class HelloWorld {
     private native void print();
     public static void main(String[] args) {
         new HelloWorld().print();
     }
     static {
         System.loadLibrary("HelloWorld");
     }
 }

Now when I try to run HelloWorld.java I get this error:

$ /usr/java1.4/bin/java HelloWorld
Exception in thread "main"
java.lang.UnsatisfiedLinkError: no HelloWorld in java.library.path
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1491)
        at java.lang.Runtime.loadLibrary0(Runtime.java:788)
        at java.lang.System.loadLibrary(System.java:834)
        at HelloWorld.<clinit>(HelloWorld.java:7)

Any tips?

Answer

@mmyers Thank you for responding. We found out that all we had to do was change System.loadLibrary to System.load and pass the full path + filename as argument, worked like a charm.

Even before doing so, we tried using the “-D” parameter and setting LD_LIBRARY_PATH but we weren’t successful.

Go figure! 🙂

Thanks again, Karen