Distutils and MinGW with C++
Gregor Thalhammer
Gregor.Thalhammer at uibk.ac.at
Mon Dec 16 03:33:54 EST 2002
Andrew Gregory wrote:
> If I wrap (SWIG) and compile (Mingw 2.0.0, gcc 3.2) a simple program
> as C code to produce a Python DLL everything works ok (using distutils
> and Python 2.2.2)
>
> But if compile as C++ I get an error message at the dllwrap stage:
>
> undefined reference to '__gxx_personality_v0'
> dllwrap exited with status 1
>
> For more complicated programs occurrences of new and delete in the
> wrapper produce "not found" errors.
>
> I noticed that distutils compiles with gcc (not g++).
>
> I changed the wrapper extension from .cxx to .cpp - but this did not
> help.
I encountered the same problem: C++ extensions are compiled and linked
with gcc instead of g++, more exactly: with the same compiler the python
binary was built.
Some solutions I found
1) Compile python with g++ (a configure option)
this isn't really necessary since to my experience you can use
extionsions compiled with g++ with python that was compiled with gcc.
2) depending on your os distutils takes the information wich compiler to
use from config/Makefile (somewhere in the python library). Make changes
there.
3) A workaround that worked for me, I am using cygwin, python 2.2, to be
included in setup.py
#workaround
import sys
m = sys.modules.get('distutils.sysconfig')
def my_customize_compiler(compiler):
if compiler.compiler_type == "unix":
(cc, opt, ccshared, ldshared, so_ext) = \
get_config_vars('CC', 'OPT', 'CCSHARED', 'LDSHARED', 'SO')
#replace gcc with g++
cc = re.sub('gcc','g++',cc)
ldshared = re.sub('gcc','g++',ldshared)
#
cc_cmd = cc + ' ' + opt
compiler.set_executables(
preprocessor=cc + " -E", # not always!
compiler=cc_cmd,
compiler_so=cc_cmd + ' ' + ccshared,
linker_so=ldshared,
linker_exe=cc)
compiler.shared_lib_extension = so_ext
m.customize_compiler = my_customize_compiler
#workaround ...
4) rewrite distutils/build_ext to use gcc or g++ depending on the file
extension
Gregor
More information about the Python-list
mailing list