title: JNI UnsatisfiedLinkError without wrong method names and with library path specified
body: <p>I'm trying to work build my very first JNI application, following this tutorial: <a href="https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html" rel="nofollow">https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html</a></p>
  
  <p>Problem Summary: While running my application, I get an java.lang.UnsatisfiedLinkError error.</p>
  
  <p>First I wrote the Class <strong>HelloJNI.java</strong>:</p>
  
  <pre><code>public class HelloJNI {
     static {
        System.loadLibrary("hello"); // Load native library at runtime
                                     // hello.dll (Windows) or libhello.so (Unixes)
     }
  
     // Declare a native method sayHello() that receives nothing and returns void
     private native void sayHello();
  
     // Test Driver
     public static void main(String[] args) {
        new HelloJNI().sayHello();  // invoke the native method
     }
  }
  </code></pre>
  
  <p>This class I compiled with:
  <strong>javac HelloJNI.java</strong>
  Next I ran <strong>javah HelloJNI</strong>
  This produced the following file <strong>HelloJNI.h</strong>:</p>
  
  <pre><code>/* DO NOT EDIT THIS FILE - it is machine generated */
  #include &lt;jni.h&gt;
  /* Header for class HelloJNI */
  
  #ifndef _Included_HelloJNI
  #define _Included_HelloJNI
  #ifdef __cplusplus
  extern "C" {
  #endif
  /*
   * Class:     HelloJNI
   * Method:    sayHello
   * Signature: ()V
   */
  JNIEXPORT void JNICALL Java_HelloJNI_sayHello
    (JNIEnv *, jobject);
  
  #ifdef __cplusplus
  }
  #endif
  #endif
  </code></pre>
  
  <p>Next I implemented <strong>HelloJNI.c</strong>:</p>
  
  <pre><code>#include &lt;jni.h&gt;
  #include &lt;stdio.h&gt;
  #include "HelloJNI.h"
  
  // Implementation of native method sayHello() of HelloJNI class
  JNIEXPORT void JNICALL Java_HelloJNI_sayHello(JNIEnv *env, jobject thisObj) {
     printf("Hello World!\n");
     return;
  }
  </code></pre>
  
  <p>Finally I compiled the c class:</p>
  
  <ul>
  <li>gcc -I"/usr/lib/jvm/java-8-oracle/include" -I"/usr/lib/jvm/java-8-oracle/include/linux" -c -Wall -Werror -fpic HelloJNI.c</li>
  <li>gcc -shared -o hello.so HelloJNI.o</li>
  </ul>
  
  <p>This produces the files hello.so and HelloJNI.o. Next I try to run the code:</p>
  
  <ul>
  <li><p>java -Djava.library.path=. HelloJNI
  This produces the error:</p>
  
  <p>Exception in thread "main" java.lang.UnsatisfiedLinkError: no hello in java.library.path
      at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1864)
      at java.lang.Runtime.loadLibrary0(Runtime.java:870)
      at java.lang.System.loadLibrary(System.java:1122)
      at HelloJNI.(HelloJNI.java:3)</p></li>
  </ul>
  
  <p>This seems to be the most common JNI error on the internet... My method names seem to be correct. I also ran:</p>
  
  <ul>
  <li>nm hello.so | grep say</li>
  </ul>
  
  <p>This gives me: <strong>00000000000006b0 T Java_HelloJNI_sayHello</strong> which seems to be correct, i.e. the compiler didn't add additional characters. I simply ran out of ideas of things I could try. Any suggestions?</p>
  
  <p>My OS: Linux Mint 13, GCC version 4.7.3, java version 1.8.0_60</p>
  
  <p>==========UPDATE===============
  When I replace <code>System.loadLibrary("hello");</code> by <code>System.load("/usr0/home/jkinable/workspace/javaIDEA/jnitest/hello.so");</code> my HelloWorld example works! However, I don't want to use an absolute path so I'm still looking for a way to use <code>System.loadLibrary("hello");</code> instead? Any suggestions? I've also tried running on a different linux system, but I get the same issue.</p>