title: Unsatisfied Link Error When Loading JNI Library
body: <p>I am writing a simple Hello World Java program to call code from a native library. However, when I run the program, I receive the following error:<br></p>
  
  <pre><code> Exception in thread "main" java.lang.UnsatisfiedLinkError: no TestJNI in java.library.path
      at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1764)
      at java.lang.Runtime.loadLibrary0(Runtime.java:823)
      at java.lang.System.loadLibrary(System.java:1044)
      at TestJNI.&lt;clinit&gt;(TestJNI.java:4)
  </code></pre>
  
  <p>Below is the code:<br>
  Java:</p>
  
  <pre><code>//filename: TestJNI.java
  
  public class TestJNI{
  
      static{
          System.loadLibrary("TestJNI");
      }   
  
      private native void helloWorld();
  
      public static void main(String[] args){
          new TestJNI().helloWorld();
     }
  }
  </code></pre>
  
  <p>C:<br></p>
  
  <pre><code>//filname:TestJNI.c
  
  #include &lt;jni.h&gt;
  #include &lt;stdio.h&gt;
  #include "TestJNI.h"
  
  JNIEXPORT void JNICALL Java_TestJNI_helloWorld(JNIEnv *env, jobject thisObj){
      printf("Hello World!\n");
      return;
  }
  </code></pre>
  
  <p>The C file is compiled with the following compiler, flags and arguments:<br>
  <code>clang -o TestJNI.jnilib -I/System/Library/Frameworks/JavaVM.framework/Headers -lc -shared TestJNI.c</code>
  <br>Then the Java application is run as below:<br>
  <code>java -Djava.library.path=. TestJNI</code></p>
  
  <p>I am compiling and running the files on Mac OS X Yosemite. Does anyone have any idea what I am doing wrong?</p>