title: JNI : Getting java.lang.UnsatisfiedLinkError for simple HelloWorld Program
body: <p>I am using Linux (Ubuntu 12.10). I have tried <a href="https://stackoverflow.com/questions/903530/how-should-i-load-native-libraries-for-jni-to-avoid-an-unsatisfiedlinkerror">this</a> question on SO and a lot others on the web, but I am not able to solve my problem.</p>
  
  <p>Here is the java file : </p>
  
  <pre><code>class HelloWorld
  {
      public native void display();
  
      static
      {
          System.loadLibrary("HelloWorld");
      }   
  
      public static void main(String args[])
      {
          HelloWorld hw = new HelloWorld();
          hw.display();
      }
  }
  </code></pre>
  
  <p>I compiled it using <code>javac HelloWorld.java</code>.</p>
  
  <p>Then I created header file from <code>.class</code> file using <code>javah -jni HelloWorld</code>. I got this header file</p>
  
  <pre><code>/* DO NOT EDIT THIS FILE - it is machine generated */
  #include &lt;jni.h&gt;
  /* Header for class HelloWorld */
  
  #ifndef _Included_HelloWorld
  #define _Included_HelloWorld
  #ifdef __cplusplus
  extern "C" {
  #endif
  /*
   * Class:     HelloWorld
   * Method:    display
   * Signature: ()V
   */
  JNIEXPORT void JNICALL Java_HelloWorld_display
    (JNIEnv *, jobject);
  
  #ifdef __cplusplus
  }
  #endif
  #endif
  </code></pre>
  
  <p>After this I created the following C file :</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "HelloWorld.h"
  
  void display();
  
  int main()
  {
      display();
      return 0;
  }
  
  void display()
  {
      printf("Hello World Naveen\n");
  }
  </code></pre>
  
  <p>and compiled this using <code>gcc -o libHelloWorld.so -fPIC -lc -shared -I/usr/lib/jvm/java-6-oracle/include/ -I/usr/lib/jvm/java-6-oracle/include/linux HelloWorld.c</code>.</p>
  
  <p>Then I did <code>echo $LD_LIBRARY_PATH=.</code>. But when I run <code>java HelloWorld</code> I am getting <code>UnsatisfiedLinkError</code></p>