title: Calling System.loadLibrary() via JNI does not load native methods
body: <p>We have a native C++ application that creates an embedded JVM.  Classes in this JVM call back into C++ object methods using SWIG wrappers (although SWIG use is not important; it could just as easily have been native function stubs produced from javah).  For example, We have a Java class with a native method like:</p>
  
  <pre><code>package net.foo;
  public class CppWrapJNI {
    public final static native long foo(
      long l, Stuff jarg1_, String s
    );
  }
  </code></pre>
  
  <p>There is a corresponding implementation in a C++ DLL:</p>
  
  <pre><code>extern "C" {
    __declspec(dllexport) jlong JNICALL 
    Java_net_foo_CppWrapJNI_1foo(
      JNIEnv *jenv, jclass jcls, 
      jlong jarg1, jobject jarg1_, jstring jarg2
    ) {
      return 1;
    }
  }
  </code></pre>
  
  <p>Let's say this DLL is named "foo.dll".  </p>
  
  <p>We then attempt to have the JVM load the DLL through JNI, using code like the following:</p>
  
  <pre><code>jclass cls = env-&gt;FindClass("java/lang/System");
  jmethodID mid = env-&gt;GetStaticMethodID(
    cls, "loadLibrary", "(Ljava/lang/String;)V"
  );
  jstring jstr = env-&gt;NewStringUTF("foo.dll");
  env-&gt;CallStaticVoidMethodV(cls, mid, jstr);
  </code></pre>
  
  <p>This all works, and the call to loadLibrary() reports no error (JNI exception processing not shown here, but we do it).  However, a later call to CppWrapJNI.foo() fails with an error like:</p>
  
  <pre><code>java.lang.UnsatisfiedLinkError: 
  net.foo.CppWrapJNI.foo(JLnet/foo/Stuff;Ljava/lang/String;)J
  </code></pre>
  
  <p>Oddly, if I write a test harness purely in Java, call loadLibrary the same way, everything works.  This was quite frustrating, since everything I could read online indicated that this should work just fine.</p>