title: python c extension, problems with dlopen on mac os
body: <p>I've taken a library that is distributed as a binary lib (.a) and header, written some c++ code against it, and want to wrap the results up in a python module.</p>
  
  <p>I've done this <a href="https://github.com/echonest/remix/tree/master/external/pydirac225" rel="nofollow noreferrer">here</a>. </p>
  
  <p>The problem is that when importing this module on Mac OSX (I've tried 10.5 and 10.6), I get the following error:</p>
  
  <pre><code>dlopen(/Library/Python/2.5/site-packages/dirac.so, 2): Symbol not found: _DisposePtr
    Referenced from: /Library/Python/2.5/site-packages/dirac.so
    Expected in: dynamic lookup
  </code></pre>
  
  <p>This looks like symbols defined in the Carbon framework aren't being properly resolved, but I'm not sure what to do about that. I am supplying <code>-framework Carbon</code> to <code>distutil.core.Extension</code>'s <code>extra_link_args</code> parameter, so I'm not sure what else I should do.</p>
  
  <p>Any help would be much appreciated.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>The compile line generated by setup.py looks like this:</p>
  
  <pre><code>gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DMACOSX -I/usr/include/ffi -DENABLE_DTRACE -arch i386 -arch ppc -pipe -Isource -I/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/numpy/core/include -I/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/numpy/numarray -I/usr/lib/python/2.5/site-packages/numpy/numarray/numpy -I/usr/lib/python/2.5/site-packages/numpy/numarray -I/usr/lib/python/2.5/site-packages/numpy/core/include -I/System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -c source/Dirac_LE.cpp -o build/temp.macosx-10.5-i386-2.5/source/Dirac_LE.o
  </code></pre>
  
  <p>The linker line looks like this:</p>
  
  <pre><code>g++ -Wl,-F. -bundle -undefined dynamic_lookup -arch i386 -arch ppc build/temp.macosx-10.5-i386-2.5/diracmodule.o build/temp.macosx-10.5-i386-2.5/source/Dirac_LE.o -Llibs/MacOSX -lDiracLE -o build/lib.macosx-10.5-i386-2.5/dirac.so -framework Carbon
  </code></pre>
  
  <p><code>otool</code> reports:</p>
  
  <pre><code>dirac.so:
   /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.4.0)
   /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
   /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.5)
  </code></pre>
  
  <p><strong>Update 2</strong>:
  On MacOS 10.5, modifying the dlopen flags from the default of <code>RTLD_NOW</code> to <code>RTLD_LAZY</code> solves the problem. However, this does not work on Mac OS 10.6. </p>
  
  <p>On 10.6, the following sequence allows the library to run properly, although I'm not sure why:</p>
  
  <ol>
  <li>python setup.py build -v </li>
  <li>run the linker line (printed to console by setup.py) again, manually.</li>
  <li>python setup.py install</li>
  </ol>
  
  <p>I'm still looking for a good answer as to how to get this to work properly. Thanks!</p>