problem building C++ extension module using distutils

harold fellermann dadapapa at gmx.net
Thu Feb 13 09:56:32 EST 2003


hello 


I try to build a C++ extension module for python 2.2 using distutils.
My setup.py has the following content:


from distutils.core import setup, Extension

module1 = Extension('network',
                    sources=['pywrapper.cpp','network.cpp'],
                    libraries=['stdc++','boost_python']
)

setup (name='network',
       version='1.0',
       ext_modules = [module1]
)


The build works fine, as long as I use only C syntax and semantics.
But trying e.g. to define a class or templates results in an error,
whenever I invoke 'python setup.py build':


running build
running build_ext
building 'network' extension
creating build
creating build/temp.linux-i686-2.2
gcc -DNDEBUG -D_FILE_OFFSET_BITS=64 -DHAVE_LARGEFILE_SUPPORT -O2
-march=i586 -mcpu=i686 -fmessage-length=0 -fPIC -fPIC
-I/usr/include/python2.2 -c pywrapper.cpp -o
build/temp.linux-i686-2.2/pywrapper.o
In file included from pywrapper.cpp:3:
network.h:16: parse error before '<' token
    [...]


Of course. network.h declares class Network which inherits a template
... gcc won't let me compile the stuff.

So: is there any possibility (option or so) to teach setup using g++
rather than gcc for the compilation. I inserted the line
"extra_compile_args=['-xc++']" within the definition of module1, but
then the mentioned gcc call warns me:

gcc: warning: '-x c++' after last input file has no effect

and I agree to him: the result stays the same :-(


Does anyone know a possibility to teach distutils.core.setup to use
the right (c++) compiler? Any clues or suggestions are welcomed!

Thanks,

- harold fellermann -




More information about the Python-list mailing list