[Pythonmac-SIG] Linking against a Python extension

Bob Ippolito bob at redivi.com
Wed Dec 21 11:34:11 CET 2005

> bob at redivi.com schrieb am 20.12.2005 22:25:28:
>> > First question: Is it possible to link against a normally built Python
>> > extension?
>> >
>> > More specifically, I want to pass the '.so' file of some Python
> extension
>> > as an extra link argument to the 'weave.inline' function. This seems
>> to
>> > work quite well on Linux. But I suspect, on Mac OS X  the answer is
> 'no'.
>> > I just want this confirmed.
>> No.  That's not the right way to do it anyway, you need to make a table
> of
>> pointers available as a PyCObject or similar and get at it that way.
> Look
>> at how something like Numeric exports its interface.
> After some hours of googling, reading and blind trying I now (hopefully)
> understand why: On OS X a Python extension is not a "shared object" (in
> the
> Linux sense) and not a dynamic library, but a (Mach-O) bundle, and a
> Mach-O
> bundle is more similar to an executable file than to an object file. In
> particular: It cannot be input to the linker again. Dead end. Period.
> Correct?

Correct.  I think it might be possible to use a MH_DYLIB as a Python
extension just by implementation detail, but distutils doesn't link that
way and you shouldn't.  Using a table of function pointers is the only
right way to share C functionality between Python extensions, despite what
you're able to make work on one platform or another.


More information about the Pythonmac-SIG mailing list