title: JNI and UnsatisfiedLinkError
body: <p>I'm doing my first steps with JNI and tried to write a simple <em>Hello Java</em> program, but it fails with this error:</p>
  
  <pre><code>Exception in thread "main" java.lang.UnsatisfiedLinkError: HelloJava.dostuff()V
          at HelloJava.dostuff(Native Method)
          at HelloJava.main(HelloJava.java:12)
  </code></pre>
  
  <p>This is my Java class:</p>
  
  <pre><code>class HelloJava {
      private native void dostuff();
      static {
          System.loadLibrary("HelloJavaDLL");
      }
  
      public static void main(String[] args) {
          System.out.println("This is from java.");
          HelloJava j = new HelloJava();
          j.dostuff();
      }
  }
  </code></pre>
  
  <p>The HelloJava.c is generated using <code>javah -jni HelloJava</code>.</p>
  
  <p>The C implementation looks like this:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;jni.h&gt;
  #include "HelloJava.h"
  
  JNIEXPORT void JNICALL Java_HelloJava_dostuff
    (JNIEnv *env, jobject this)
  {
      printf("And this comes from C ! :)\n");
  }
  </code></pre>
  
  <p>I compiled it on Windows using gcc to a shared library (.dll).</p>
  
  <p>Now running the Java .class File the Exception from above occurs. <strong>Can you tell me why this error appears ?</strong></p>
  
  <p><em>And by-the-way, can you tell me how I can use JNI with C++ ?</em></p>
  
  <h2>UPDATE</h2>
  
  <p>Maybe you want to try it yourself ? I really can't find the issue.Here is a link to <a href="http://www.mediafire.com/?cdnjhmysk6ep0nc" rel="nofollow noreferrer">MediaFire</a> where you can download a .zip file containing all files (event the compiled ones).</p>
  
  <p>The retried everything but it's still the same issue.<br>
  Theese are the steps I did:</p>
  
  <ol>
  <li>Write Hello.java</li>
  <li>Compile Hello.java using <code>javac Hello.java</code></li>
  <li>Create a header file using <code>javah -jni Hello</code></li>
  <li>Write the Hello.c file</li>
  <li>Compile the Hello.c file using<br>
  <code>gcc Hello.c -shared -o Hello.dll -I"C:\Java\jdk1.7.0\include" -I"C:\Java\jdk1.7.0\include\win32"</code></li>
  <li>Execute Hello.class using <code>java Hello</code></li>
  </ol>
  
  <p>Thanks.</p>
  
  <h2>SOLUTION</h2>
  
  <p>Adding <code>-Wl,--kill-at</code> to the gcc command fixes the problem, according to this <a href="https://stackoverflow.com/questions/3689074/build-a-jni-dll-using-mingw">question</a> here.<br>
  Thanks to A.H. for his help !</p>