[Distutils] limiting symbols in C module

M.-A. Lemburg mal at egenix.com
Fri Sep 10 11:47:24 CEST 2004

Brandon Craig Rhodes wrote:
> 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?

There are probably a few cases where this may cause problems,
but in general, I don't see why distutils should try to strip
symbols from C extensions.

Is there a specific problem you are trying to solve ?

> 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?

You could write you own distutils extension to perform this
step in the linking phase. However, I'm not sure whether strip
is available on all Unix systems or whether the VCC compiler
on Windows has an option for this.

Marc-Andre Lemburg

Professional Python Services directly from the Source  (#1, Sep 10 2004)
 >>> Python/Zope Consulting and Support ...        http://www.egenix.com/
 >>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
 >>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::

More information about the Distutils-SIG mailing list