[Distutils] Compiling / Installing extensions

Thomas Heller thomas.heller@ion-tof.com
Tue, 8 Feb 2000 11:39:56 +0100


> > so in build_ext.py line 225 should look like
> >
> >             if self.compiler.compiler_type == 'msvc':
> >                 extra_args.append('/export:init%s'%extension_name)
>
> OK, except you mean line 238 in the current CVS version.  ;-) At any
> rate, done.  Any Windows people who feel a deep attachment for .def
> files better speak up now.  More seriously, is there any reason a Python
> extension module needs to export any symbols other than
>    "init%s" % extension_name
> ???
I suggest:
        if self.compiler.compiler_type == 'msvc':
            def_file = build_info.get ('def_file')
            if def_file is None:
                source_dir = os.path.dirname (sources[0])
                ext_base = (string.split (extension_name, '.'))[-1]
                def_file = os.path.join (source_dir, "%s.def" % ext_base)
                if not os.path.exists (def_file):
                    self.warn ("file '%s' not found: " % def_file +
                               "might have problems building DLL")
                    def_file = None

            if def_file is not None:
                extra_args.append ('/DEF:' + def_file)
            else:
                modname = string.split (extension_name, '.')[-1]
                extra_args.append('/export:init%s'%modname)

split(extension_name) is needed for extensions living in package
directories.

If the developer bothers to write a def file, it should be used.
Otherwise guess the exported symbol.
Note:
For normal python extensions, only this single export is used.
This may be different for COM-modules for example...

Thomas