title: Linking a dynamic library (libjvm.dylib) in Mac OS X (rpath issue)
body: <p>I do have an application that requires linkage with <code>libjvm</code> (a library from the JDK needed to do JNI bindings). When I tell the location of <code>libjvm.dylib</code> using <code>-L</code> it successfully compiles and links. However when I run the binary I get:</p>
  
  <pre><code>dyld: Library not loaded: @rpath/libjvm.dylib
    Referenced from: &lt;my home directory&gt;/./mybinary
    Reason: image not found
  </code></pre>
  
  <p>So far I found out that I can run my binary specifying LD_LIBRARY_PATH like so:</p>
  
  <pre><code>LD_LIBRARY_PATH=&lt;path to libfolder installation&gt; ./mybinary
  </code></pre>
  
  <p>But of course I do not want that. Why should I specify the exact location anyway if I have to give it again and again each time I start the application?!</p>
  
  <p>I also learned that dynamic libraries on mac os x do get a kind of stamp which tells there location. However I don't know what <code>rpath</code> is (seems like a variable to me, but how can I set it during linking?).</p>
  
  <p>The application is built using haskell, but I can equally well link the object files manually using <code>ld</code>. However, I'm stuck on that rpath thing - is it maybe special to the JDK libraries?</p>
  
  <p>Here is what I do in order to build:</p>
  
  <pre><code>ghc --make Main.hs mycbinding.o -ljvm -L&lt;javahome&gt;/jre/lib/server -o mybinary
  </code></pre>