title: dylib cannot load libstd when compiled in a workspace
body: <p>I have a project with the following structure:</p>
  
  <pre class="lang-none prettyprint-override"><code>Cargo.toml
  my_script.py
  my_lib:
      - Cargo.toml
      - src
  my_bin:
      - Cargo.toml
      - src
  </code></pre>
  
  <p>Where:</p>
  
  <ul>
  <li><code>my_lib</code> is a Rust library with <code>crate-type = ["dylib"]</code></li>
  <li><code>my_bin</code> is a Rust binary application using <code>my_lib</code></li>
  <li><code>my_script.py</code> is a Python 3 script that also uses <code>my_lib</code></li>
  </ul>
  
  <p>The root <code>Cargo.toml</code> contains a basic workspace declaration:</p>
  
  <pre><code>[workspace]
  members = [
      "my_lib",
      "my_bin"
  ]
  </code></pre>
  
  <p>Everything works properly if I execute <code>cargo build</code> and <code>cargo run -p my_bin</code>. The problem comes with the Python script.</p>
  
  <p>In this script, I load the <code>my_lib</code> lib file using the following code:</p>
  
  <pre class="lang-py prettyprint-override"><code>from ctypes import cdll
  from sys import platform
  
  if platform == 'darwin':
      prefix = 'lib'
      ext = 'dylib'
  elif platform == 'win32':
      prefix = ''
      ext = 'dll'
  else:
      prefix = 'lib'
      ext = 'so'
  
  # Working path:
  # lib_path = './my_lib/target/debug/{}my_lib.{}'.format(prefix, ext)
  
  # Buggy "Library not loaded: @rpath/libstd-d00eaa6834e55536.dylib" path:
  lib_path = './target/debug/{}my_lib.{}'.format(prefix, ext)
  
  lib = cdll.LoadLibrary(lib_path)
  my_func = lib.my_func
  my_func()
  </code></pre>
  
  <p>If I use the library file from the <em>library directory</em> (<code>./my_lib/target/...</code>), the script has no problem loading the library and executing its functions.</p>
  
  <p>But if I use the library file from the <em>workspace directory</em> (<code>./target/...</code>) I get the following error when trying to load the library:</p>
  
  <pre class="lang-none prettyprint-override"><code>OSError: dlopen(./target/debug/libpeglrs.dylib, 6): Library not loaded: @rpath/libstd-d00eaa6834e55536.dylib
  </code></pre>
  
  <p>In the same fashion, trying to execute <code>my_bin</code> directly from the workspace target directory yields the same error (even though <code>cargo run -p my_bin</code> work flawlessly).</p>
  
  <p>Using the software "Dependency Walker", I found that the <code>my_lib</code> library cannot find the Rust <code>libstd</code> library (has the previous error message explain).</p>
  
  <p>Manually exporting the path that contains the Rust toolchain library into the environment <code>PATH</code> fixes the issue. This is however far from ideal and not portable. I also don't understand why this issue is only occurring <em>when using the <strong>workspace</strong> target</em>.</p>
  
  <p>So, why can't the workspace target find rust's <code>libstd</code> when each project target can? Is there a way to fix this issue that wouldn't require to find the toolchain path and modify an environment variable?</p>