[Distutils] mingw and environment variables
dobesv at gmail.com
Tue May 22 19:19:06 CEST 2007
It seems to be a problem with distutils currently that g++ isn't used to
link at the appropriate time. Ideally you'd split linking into C++ and C
variations, and detect whether the C++ compiler was used and use the
C++ linker if it was.
And, a bug related to this, is that you can't easily override the linker
when using mingw; the customize_compiler() function checks for a type of
"""Do any platform-specific customization of a CCompiler instance.
Mainly needed on Unix, so we can plug in the information that
varies across Unices and is stored in Python's Makefile.
if compiler.compiler_type == "unix":
But the mingw compiler (which is unix compatible) has a compiler_type
'mingw32', not 'unix'.
The easiest "band-aid" patch would be to use
if compiler.compiler_type in ("unix", "mingw32"):
but I wonder whether:
if isinstance(compiler, UnixCCompiler):
would be more appropriate?
The workaround I came up with is:
# Force g++ for linking
old_customize_compiler = distutils.sysconfig.customize_compiler
if compiler.compiler_type == 'mingw':
compiler.set_executables(linker_so='g++ -mno-cygwin -shared')
distutils.sysconfig.customize_compiler = customize_compiler
More information about the Distutils-SIG