title: JavaCpp: How to Specify the Native Library?
body: <p>Where does JavaCpp look for the native library <code>libmynativelib.so</code> when it creates the jni library, <code>/linux-x86_64/libjnimynativelib.so</code>?</p>
  
  <p>JavaCpp is told about the C++ header and shared library using the <code>@Platform</code> annotation like this:</p>
  
  <pre><code>@Platform(include={"MyLibraryHeader.h"}, link = "mynativelib")
  @Namespace("mynamespace")
  public class MyLibrary {
    ...
  }
  </code></pre>
  
  <p>The above Java class is then compiled and run through JavaCpp like this:</p>
  
  <pre><code>javac -cp javacpp.jar MyLibrary.java
  java -jar javacpp.jar -cp ../..   # classpath is parent of com/mypackage dir
  </code></pre>
  
  <p>Then JavaCpp output:</p>
  
  <pre><code>Generating /&lt;projpath&gt;/jniMyLibrary.cpp
  Compiling /&lt;projpath&gt;/linux-x86_64/libjniMyLibrary.so
  g++ -I/usr/lib/jvm/java-7-openjdk-amd64/include -I/usr/lib/jvm/java-7-openjdk-amd64/include/linux &lt;path&gt;/jniMyLibrary.cpp -Wl,-rpath,$ORIGIN/ -march=x86-64 -m64 -Wall -O3 -fPIC -shared -s -o /&lt;projpath&gt;/linux-x86_64/libjnimynativelibrary.so -lmynativelib
  </code></pre>
  
  <p>Which gives this error:</p>
  
  <pre><code>/usr/bin/ld: cannot find -lmynativelib
  </code></pre>
  
  <p>g++ is not finding <code>libmynativelib.so</code> either in the current dir () or in the linux-x86_64 subdir.</p>
  
  <p><code>LD_LIBRARY_PATH=&lt;projdir&gt;</code> doesn't help.</p>
  
  <p>What is the recommended way to tell JavaCpp which native library to load?</p>