[Distutils] More (Windows) comments on distutils-0.1.2

Thomas Heller thomas.heller@ion-tof.com
Thu, 13 Jan 2000 15:34:23 +0100


1. Python extensions for Windows MUST be linked with
the /MD switch to use the multithreaded runtime
library. Optimizations are also enabled by the following
line:

> class MSVCCompiler (CCompiler) :
>     def __init__ (self,
>         [...]
>         self.compile_options = [ '/nologo', '/Ox', '/MD', '/GD' ]

2. In build_ext.py I find the following code:

>    def build_extensions (self, extensions):
>   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)

Doesn't this belong into msvccompiler.py?

We do not need any stinkin' DEF-files, if we use the link options
/EXPORT and /BASE. The following code builds the required arguments:

>        if def_file is not None:
>            extra_args.append ('/DEF:' + def_file)
>        else:
>            # if no def file is found, export the init<name> function
>            # and calculate a random base address
>            extra_args.append ('/EXPORT:init' + extension_name)
>            import whrandom
>            base = whrandom.randint (0x1000, 0x8000) * 0x10000
>            extra_args.append ('/BASE:0x%x' % base)

Regards,

Thomas Heller
ION-TOF GmbH