[SciPy-dev] cluster/src/vq_wrap.cpp not being compiled with C++

Pearu Peterson pearu at cens.ioc.ee
Wed Sep 4 16:25:54 CDT 2002

On Wed, 4 Sep 2002, Skip Montanaro wrote:

> I'm trying to build SciPy on a Solaris system (sunos 5.8) using Sun's C, C++
> and Fortran compilers.  I've fiddled and faddled 'til it got down to
> compiling .../scipy/cluster.  It goes to compile the vq_wrap.cpp file and
> tries compiling it with 'cc' instead of 'CC'.  Distutils generates this
> command:
>     cc -DNDEBUG -O -I/home/skip/local/SunOS/include/python2.2 -c
>     cluster/src/vq_wrap.cpp -o build/temp.solaris-2.8-sun4u-2.2/vq_wrap.o 
> which generates this message:
>     cc: No input file specified, no output generated
> If I simply change 'cc' to 'CC' it compiles fine.  I would have thought
> distutils would recognize the need to use 'CC' if the file extension was
> '.cpp'.  If I try running
>     python setup.py build_ext --compiler=CC
> distutils raises a PlatformError:
>     don't know how to compile C/C++ code on platform 'posix' with 'CC'
>     compiler
> I don't see anything like a command/build_cpplib.py file which might tell
> how to build C++ extensions.
> Where should I be looking for clues?

This is a known problem with distutils that for compiling C++ extensions
certain hacks are needed. Here are some solutions that people have

1) Build Python with C++ compiler

2) Edit python2.2/config/Makefile by changing CC variable and do something
with libpython2.2.a --- what exactly, I don't remember now, but I think it
is described in wxPython installation notes.

3) I use the following codelet in my C++ extension setup.py files that
you could modify to your needs easily:

#+++HACK: replace linker gcc with g++ +++++++++++
gpp_exe = 'g++'
gcc_exe = 'gcc'
from distutils import sysconfig
save_init_posix = sysconfig._init_posix
def my_init_posix():
    g = sysconfig._config_vars
    for n,r in [('LDSHARED',gpp_exe),('CC',gcc_exe)]:
        if g[n][:3]=='gcc':
            print 'my_init_posix: changing %s = %r'%(n,g[n]),
            g[n] = r+g[n][3:]
            print 'to',`g[n]`
sysconfig._init_posix = my_init_posix
I like this hack because one does not need to mess with Python
defaults that would be not always desired or possible.


More information about the Scipy-dev mailing list