title: Including and distributing third party libraries with a Python C extension
body: <p>I'm building a C Python extension which makes use of a &quot;third party&quot; library— in this case, one that I've built using a separate build process and toolchain. Call this library <code>libplumbus.dylib</code>.</p>
  <p>Directory structure would be:</p>
  <pre><code>grumbo/
    include/
      plumbus.h
    lib/
      libplumbus.so
    grumbo.c
    setup.py
  </code></pre>
  <p>My <code>setup.py</code> looks approximately like:</p>
  <pre><code>from setuptools import Extension, setup
  
  native_module = Extension(
      'grumbo',
      define_macros = [('MAJOR_VERSION', '1'),
                       ('MINOR_VERSION', '0')],
      sources       = ['grumbo.c'],
      include_dirs  = ['include'],
      libraries     = ['plumbus'],
      library_dirs  = ['lib'])
  
  
  setup(
      name = 'grumbo',
      version = '1.0',
      ext_modules = [native_module] )
  </code></pre>
  <p>Since libplumbus is an external library, when I run <code>import grumbo</code> I get:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  ImportError: dlopen(/path/to/grumbo/grumbo.cpython-37m-darwin.so, 2): Library not loaded: lib/libplumbus.dylib
    Referenced from: /path/to/grumbo/grumbo.cpython-37m-darwin.so
    Reason: image not found
  </code></pre>
  <p><strong>What's the simplest way to set things up so that <code>libplumbus</code> is included with the distribution</strong> and properly loaded when <code>grumbo</code> is imported? (Note that this should work with a virtualenv).</p>
  <p>I have tried adding <code>lib/libplumbus.dylib</code> to <code>package_data</code>, but this doesn't work, even if I add <code>-Wl,-rpath,@loader_path/grumbo/lib</code> to the Extension's <code>extra_link_args</code>.</p>