[Distutils] limiting symbols in C module

Brandon Craig Rhodes brandon at ten22.rhodesmill.org
Fri Sep 10 10:20:52 CEST 2004


Python modules are often written as single .c files (sometimes quite
large) so that everything can be declared "static" except for the
init<module>() function; and though the Extending and Embedding
document is unfortunately rather quiet on the many issues that arise
during linking, the suggestion seems to be that minimizing the number
of symbols exported by the module is good.

As I update a Python module that provides an interface to an extensive
collection of existing C functions, I note that the process of linking
my module .o with all of the .o files produced by compiling the other
code produces a Python module with a huge number of symbols.

  1) Is this bad and should be avoided?

I note that running strip(1) with the "-K" option allows me to strip
all defined symbols from the module except for the one init<module>
symbol that I want to keep.

  2) Do the distutils know how to perform this operation?  This would
     even allow normal Python modules - that have all original code
     rather than being linked with existing .o files - to be written
     as several manageable .c files rather than one huge one.

  3) Can the distutils be induced to perform such a strip even if they
     do not quite know how themselves, or is the whole issue going to
     be different enough on, say, Windows, that it cannot be handled
     portably with the distutils in their current form?  Is there a
     portable way to put the strip command within a stanza that will
     only run on appropriately Unixish systems?

-- 
Brandon Craig Rhodes   brandon at rhodesmill.org   http://rhodesmill.org/brandon



More information about the Distutils-SIG mailing list