title: JNI C++ UnsatisfiedLinkError When Calling Method
body: <p>I have been trying to create a simple JNI Test with C++. For Java I am using Eclipse, and for C++ I am using Visual Studio 2013. I followed the directions on other pages on StackOverFlow but nothing really seems to work. The error occurs when I try calling the native method in java listed in C++. </p>
  
  <p>Thanks for your time.</p>
  
  <h1>Header.h</h1>
  
  <pre><code>#include &lt;jni.h&gt;;
  using namespace std;
  #ifndef Header
  #define Header
  JNIEXPORT void JNICALL Java_base_Main_print(JNIEnv *env, jobject obj);
  #endif
  </code></pre>
  
  <h1>Edited Header.h (solution which worked)</h1>
  
  <pre><code>#include &lt;jni.h&gt;;
  using namespace std;
  
  #ifndef Header
  #define Header
  
  extern "C" {
  JNIEXPORT void JNICALL Java_base_Main_print(JNIEnv *env, jobject obj);
  }
  #endif
  </code></pre>
  
  <h1>JNIHelloWorld.cpp</h1>
  
  <pre><code>#include "Header.h";
  
  JNIEXPORT void JNICALL Java_base_Main_print(JNIEnv *env, jobject obj) {
      printf("This is a JNI tester\n");
      //return;
  }
  </code></pre>
  
  <h1>JavaCode</h1>
  
  <pre><code>package base;
  public class Main {
      static {System.loadLibrary("JNIHelloWorld");}
      public static void main(String args[]){
          Main m = new Main();
          m.print();
      }
      public native void print();
  }
  </code></pre>
  
  <h1>Error</h1>
  
  <pre><code>Exception in thread "main" java.lang.UnsatisfiedLinkError: base.Main.print()V
      at base.Main.print(Native Method)
      at base.Main.main(Main.java:9)
  </code></pre>