Q: Shared python extension module calling another shared library?

Tom Vrankar no at spam.net
Sun Oct 24 02:11:48 EDT 1999


I've finally tried to write a python extension module, just for practice. I 
understand the basics but am really not clear at all about which objects need 
me to call INCREF or DECREF, and which ones are already taken care of. I'll 
have to cruise the website some more to find a complete example.

But my first problem is linking libraries. I'm trying to write an extension 
module as a shared library on HP-UX using gcc that in turn calls another 
shared library that appears to be C++ based -- it even requires its own 
version of the standard C library. In case anyone has any direct experience, 
the library I'm trying to wrap is Mentor Graphics' DFI. I've written in python 
for years, and have written dfi programs for more years. I think that python 
would make a great language to access the dfi to hide all that pointer-and 
linked-lists crap so that users can do their own dfi programs.

My approach was to follow the cookbook as directed in the HTML documentation, 
using Misc/Modules.pre.in and Setup.in. A vanilla extension module worked fine 
(a function to return its arguments; yay!). I then wrote another to wrap the 
dfi. It calls dfi_version() in the shared dfi library -- which just returns a 
pointer to a string -- and added the gcc switches specified in Mentor's 
dfilink script for the default shared library. Although make returns 
successfully, import fails (but it's unhelpfully vague about what it doesn't 
like).

I tried to change the Setup file to include compile switches that statically 
link the dfi library to my shared library module, but that won't even link.

I realize I don't completely understand all the nuances of shared libraries, 
particularly when I've got one calling another. And the dfi library uses a c++ 
library that claims to override some of the standard C functions. Is this a 
complication, or does dynamic linking make sure the proper libraries satisfy 
unresolved globals in different C modules?

Does anyone have any suggestions or tips on how to go about linking this mess 
together? Or how at least to debug whatever problem import has? Any help is 
appreciated.

								twv@

-- 
                         ---------------------------------
                                               Tom Vrankar
                                            twv at ici.net
                                 http://home.ici.net/~twv/
                                         Rhode Island, USA





More information about the Python-list mailing list