title: Java and JNI - Loading dll libraries only works on my computer
body: <p>I'm facing some annoying problems to get my java application working with external c++ dlls, through JNI. The libraries are located inside packages. I copy them to a temporary folder when I need to load them into virtual machine. The dlls are the next:</p>
  
  <p>libcurld.dll;
  libfftw3f-3.dll;
  libmad.dll;
  libsamplerate.dll;
  main.dll;</p>
  
  <p>The main.dll is the one that implements the native method declared on the java side. This dll depends on the above to run properly. I only compiled the main.ddl on visual studio, one binary for 7 other for xp. The others were downloaded and simply linked. I run the next method to load the libraries on java:</p>
  
  <pre><code>public static boolean loadBinaries(){
      String os = System.getProperty("os.name").toLowerCase();
      ArrayList&lt;String&gt; bins = new ArrayList&lt;String&gt;();
  
      if(os.indexOf("windows 7") &gt;= 0){
          bins.add("/nm/metadata/bin/win/libcurld.dll");
          bins.add("/nm/metadata/bin/win/libfftw3f-3.dll");
          bins.add("/nm/metadata/bin/win/libmad.dll");
          bins.add("/nm/metadata/bin/win/libsamplerate.dll");
          bins.add("/nm/metadata/bin/win/seven/main.dll");
      }
      else if(os.indexOf("windows xp") &gt;= 0){
          bins.add("/nm/metadata/bin/win/libcurld.dll");
          bins.add("/nm/metadata/bin/win/libfftw3f-3.dll");
          bins.add("/nm/metadata/bin/win/libmad.dll");
          bins.add("/nm/metadata/bin/win/libsamplerate.dll");
          bins.add("/nm/metadata/bin/win/xp/main.dll");
      }
  
      File f = null;
      for(String bin : bins){
          InputStream in = FileManager.class.getResourceAsStream(bin);
          byte[] buffer = new byte[1024];
          int read = -1;
          try {
              String[] temp = bin.split("/");
              f = new File(TEMP_FOLDER + "/" + temp[temp.length-1]);
              File realF = new File(f.getAbsolutePath());
              if(realF.exists())
                  f.delete();
  
              FileOutputStream fos = new FileOutputStream(realF);
  
              while((read = in.read(buffer)) != -1) {
                  fos.write(buffer, 0, read);
              }
              fos.close();
              in.close();
  
              System.load(f.getAbsolutePath());
          } catch (IOException e) {
              e.printStackTrace();
              return false;
          }
      }
  
      return true;
  }
  </code></pre>
  
  <p>The executable jar works always perfectly on my machine, but not in others... I got the next errors from my tests:</p>
  
  <pre><code>(xp)
  Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\temp\main.dll: Can't find dependent libraries at java.lang.ClassLoader$NativeLibrary.load(Native Method)...
  
  (seven)
  C:\temp\main.dll: The application has failed to start because its side-by-side configuration is incorrect...
  </code></pre>
  
  <p>All the dlls are well written in the temp folder and, as I said, this works well in my computer. I had thought this could be because compiling in debug mode on VS. Unfortunately, turning it to release didn't change anything, unless returning smaller binaries.</p>
  
  <p>What can this be? Is some configuration detail missing on visual studio?
  Thanks in advance.</p>