[Pyrex] Problems with compiling a module using a C++ compiler
Matthias Baas
baas at ira.uka.de
Mon Aug 4 08:37:16 CEST 2003
Hi,
I have a problem with Pyrex 0.8.2 on Windows (XP) and VC6. When I try to
compile Pyrex generated C code actually using the C++ compiler (i.e. my
Pyrex output file has suffix .cpp) then the compiler generates errors.
Here's an example Pyrex file:
##########################################
# File: xtest.pyx
# An arbitrary extension type...
cdef class MyClass:
def __init__(self):
pass
# A function that expects a MyClass object as input and
# assigns it to a local variable of the same type
def foo(MyClass mc):
cdef MyClass local_mc
local_mc = mc
##########################################
I'm using the following setup script to compile the module. Note that I
call the output file xtest.cpp instead of just xtest.c so when compiling
the module the C++ compiler will be invoked.
##########################################
# File: setup.py
from distutils.core import setup, Extension
import os
# Run Pyrex and generate a *.cpp (!) file
os.system("pyrexc -o xtest.cpp xtest.pyx")
setup(name="xtest",
ext_modules=[Extension("xtest", ["xtest.cpp"])])
##########################################
When I try to compile the module I get two errors saying that the left hand
operand must be an L value.
The offending lines are these:
((PyObject*)__pyx_v_local_mc) = Py_None;
...
((PyObject *)__pyx_v_local_mc) = ((PyObject *)__pyx_v_mc);
The problem is the cast on the left hand side. I've never seen that before
and don't know if this is valid C/C++ code. But anyway, VC6 chokes on it
(however, it does not complain when compiled as pure C code). Can this be
changed in Pyrex so that casts only appear on the right hand side? (in this
particular case the second line wouldn't even require a cast as both
variables are of the same type)
I'm using the .cpp suffix because I'm trying to wrap a C++ library which
has to be compiled using a C++ compiler (and needs the C++ runtime library).
- Matthias -
More information about the Pyrex
mailing list