title: JNI C++ DLL - 'UnsatisfiedLinkError: %1 is not a valid Win32 application'
body: <p>I am trying to actually get JNI working before I dive in with my actual code, but after I compile a DLL from C++ and run my Java application I get:</p>
  
  <pre><code>Exception in thread "main" java.lang.UnsatisfiedLinkError: &lt;snip&gt;\workspace\JNI test\native\jnitest.dll: %1 is not a valid Win32 application
      at java.lang.ClassLoader$NativeLibrary.load(Native Method)
      at java.lang.ClassLoader.loadLibrary1(Unknown Source)
      at java.lang.ClassLoader.loadLibrary0(Unknown Source)
      at java.lang.ClassLoader.loadLibrary(Unknown Source)
      at java.lang.Runtime.loadLibrary0(Unknown Source)
      at java.lang.System.loadLibrary(Unknown Source)
      at net.condorcraft110.jnitest.JNITest.main(JNITest.java:11)
  </code></pre>
  
  <p>Having Googled this for a bit, I know that this is usually caused by trying to load a 64 bit DLL with a 32 bit JVM. However, my JVM is 64 bit, as evidenced by <code>sun.arch.data.model</code> equalling 64.</p>
  
  <p>My makefile:</p>
  
  <pre><code>CLASSPATH = ../bin
  
  vpath %.class $(CLASSPATH)
  
  all : jnitest.dll
  
  jnitest.dll : jnitest.o
      g++ -m64 -Wl,--add-stdcall-alias -shared -o $@ $&lt;
  
  jnitest.o : jnitest.cpp jnitest.h
      g++ -m64 -I"C:\Program Files\Java\jdk1.7.0_51\include" -I"C:\Program Files\Java\jdk1.7.0_51\include\win32" -c $&lt; -o $@
  
  jnitest.h : net/condorcraft110/jnitest/JNITest.class
      javah -verbose -classpath $(CLASSPATH) -o jnitest.h net.condorcraft110.jnitest.JNITest
  
  clean :
      rm jnitest.h jnitest.o jnitest.dll
  </code></pre>
  
  <p>JNITest.java:</p>
  
  <pre><code>package net.condorcraft110.jnitest;
  
  public class JNITest
  {
      private static native void test();
  
      public static void main(String[] args)
      {
          System.out.println("sun.arch.data.model = " + System.getProperty("sun.arch.data.model"));
  
          System.loadLibrary("jnitest");
  
          test();
      }
  }
  </code></pre>
  
  <p>jnitest.h as generated by javah:</p>
  
  <pre><code>/* DO NOT EDIT THIS FILE - it is machine generated */
  #include &lt;jni.h&gt;
  /* Header for class net_condorcraft110_jnitest_JNITest */
  
  #ifndef _Included_net_condorcraft110_jnitest_JNITest
  #define _Included_net_condorcraft110_jnitest_JNITest
  #ifdef __cplusplus
  extern "C" {
  #endif
  /*
   * Class:     net_condorcraft110_jnitest_JNITest
   * Method:    loadPlugins
   * Signature: ()V
   */
  JNIEXPORT void JNICALL Java_net_condorcraft110_jnitest_JNITest_test
    (JNIEnv *, jclass);
  
  #ifdef __cplusplus
  }
  #endif
  #endif
  </code></pre>
  
  <p>jnitest.cpp:</p>
  
  <pre><code>using namespace std;
  
  #include &lt;jni.h&gt;
  #include &lt;iostream&gt;
  #include "jnitest.h"
  
  extern "C" JNIEXPORT void JNICALL Java_net_condorcraft110_jnitest_JNITest_test(JNIEnv *env, jclass clazz)
  {
      cout &lt;&lt; "jni test successful" &lt;&lt; endl;
  }
  </code></pre>
  
  <p>Anyone know why this isn't working?</p>
  
  <p><strong>Edit:</strong> <code>java.library.path</code> definitely points to <code>native</code>, as set up in an Eclipse run configuration.<br>
  <strong>Edit 2:</strong> the DLL works if I compile it with VS2013, but I <em>really</em> don't want to tie my project to Visual Studio if I can help it.</p>