[Pythonmac-SIG] building extensions that link against dynamic libraries (revisited)

Robert Tolbert bob at eyesopen.com
Mon Apr 26 00:47:49 EDT 2004


I hate to dredge up an old topic, but I've spent more time chasing this 
weird problem and am still befuddled as to why I can't get this to work.

The original question was posted here:

http://mail.python.org/pipermail/pythonmac-sig/2004-January/009911.html

where I asked some questions about importing an extension that is linked 
against a shared dynamic library that I've also built. In a nutshell, I 
am wrapping a large C++ API in Python using SWIG. I can built the base 
C++ libraries as either static libs or dynamic libs. I can built the 
extension linked against either of these. And here is where the 
difference lies.

If I link against the static libraries, my extension loads and works 
just fine.

If I link against the dynamic libraries, Python hangs trying to import 
the extension. Ctrl-C won't interupt it, I have to Ctrl-Z and kill -9 to 
get it to stop.

Interestingly, Fink's python can import and use either extension as 
built above. The problem is only with /usr/bin/python on Panther.

As a follow-up to the last discussion, I have done several things to try 
and rule out several of the issues people have noted in emails and the 
FAQ. 

1. I have switched to building the extension using distutils; still 
won't load.
2. I have tried building on a second Panther machine that never had 
Jaguar (old system python) and has never had Fink. So I could rule out 
the problems people have noted due to multiple Python's being installed.
3. I've used otool on the extension .so to see which 
libraries/Frameworks it is dependent on. I've made sure that 
DYLD_LIBRARY_PATH points to the directory containing my C++ dynamic 
libraries. This was enough to make sure Fink's python can load the 
modules just fine. My wonder now is whether /usr/bin/python actually 
honors DYLD_LIBRARY_PATH, or whether the is some other location I need 
to put my .dylibs to help it find them.

At the end of the day, I can probably get customers to use Fink or build 
their own Python into /usr/local/bin but it sure would be nice to have 
this work with the system python.

Bob Tolbert



More information about the Pythonmac-SIG mailing list