title: Linking shared libraries in same directory
body: <p>I'm using CMake to build two shared libraries (<code>.so</code> files). They get built into separate directories, but on the install step they get copies into the same directory. One of them links with the other. And both get loaded dynamically from another process.</p>
  
  <p>The first problem is that apparently CMake does not set an rpath on the <code>.so</code> files on OS X (not tested on other platforms). In <code>CMakeLists.txt</code> I have</p>
  
  <pre><code>set(CMAKE_INSTALL_PREFIX ../dist)
  set(MACOSX_RPATH YES)
  set(INSTALL_NAME_DIR YES)
  </code></pre>
  
  <p>And the <code>CMakeLists.txt</code> files for the two libraries get included using</p>
  
  <pre><code>add_subdirectory(./a "${CMAKE_BINARY_DIR}/a")
  add_subdirectory(./b "${CMAKE_BINARY_DIR}/b")
  </code></pre>
  
  <p>But running <code>otool -l</code> on the resulting <code>.so</code> files shows no <code>LC_RPATH</code> entry.</p>
  
  <p>Also, which path would need to be set in the RPath (of <code>a</code>) so that when the linker loads <code>a.so</code>, it can find <code>b.so</code> which is in the same directory (<code>dist/</code>). The executable from which <code>a</code> gets loaded is in a different place.</p>
  
  <p>I've tried <code>@executable_path/</code>, <code>@executable_path/../</code>, <code>@origin/../</code>, but none seem to work.</p>