[Distutils] linking modules to a shared library

Stephen Langer stephen.langer at nist.gov
Fri Sep 30 19:57:03 CEST 2005


Hi --

I have a problem that is similar to one discussed in a thread from a  
year ago,
http://mail.python.org/pipermail/distutils-sig/2004-September/ 
004160.html, but that thread doesn't quite have a resolution in the  
archives.

I'd like to use distutils to build a bunch of python modules that all  
link to the same shared library.  The shared library is all C++  
code.  On Linux, without distutils, I can build the libraries like this:

   g++ -o libBase.so -shared base.C    # builds the common shared  
library
   g++ -o _mymodule.so -shared mymodule.C -lBase # builds a python  
module
                                                 # linking to the  
shared lib.
   g++ -o _othermodule.so -shared othermodule.C -lBase # and so on

_mymodule.so and _othermodule.so can be imported by Python, and share  
a single copy of the code in libBase.so.

On the Mac I can get the same effect with this:

   g++ -dynamiclib base.C -o libBase.dylib
   g++ -o _mymodule.so mymodule.C -lBase -bundle -undefined  
dynamic_lookup -flat_namespace
   g++ -o _othermodule.so othermodule.C -lBase -bundle -undefined  
dynamic_lookup -flat_namespace

Is it possible to create libBase portably with distutils?  It's  
possible to do it on Linux by  subclassing build_ext.build_ext and  
explicitly using self.compiler.compile() and  
self.compiler.link_shared_lib() to build the shared library before  
calling build_ext.build_ext.build_extensions().  But the same thing  
on Mac OS X only creates libBase.so, whereas I need it to create  
libBase.dylib.

If it matters, I'm using OS X 10.4.2 and gcc 3.3, with Python 2.3.5.

Many thanks,
           Steve

--
-- EMail: stephen.langer at nist.gov                    Phone: (301)  
975-5423 --
-- WWW:  http://math.nist.gov/mcsd/Staff/SLanger/    Fax:   (301)  
990-4127 --
-- Mail: NIST; 100 Bureau Drive -- Stop 8910; Gaithersburg, Md   
20899-8910 --

-- "I don't think this will work.  That's why it's  
science."               --
--                                      Naomi Langer,  17 Feb  
2003         --




More information about the Distutils-SIG mailing list