Abstract class in Cython

59 views
Skip to first unread message

Jerry Qi

unread,
Nov 18, 2016, 1:28:20 PM11/18/16
to cython-users
To make things simple, I am using an example to illustrate the problem. In C++, I have an abstract class object with some functions like get/set color, rectangle and circle are inherited from object. They are all included in Rectangle.h and Rectangle.cpp. When I wrap them up in Cython, if I put everything together like following, everything works.

cdef extern from "Rectangle.h" namespace "shapes":
cdef cppclass Object:
   ...getColor()
   ...setColor()
  //just function no constructors

cdef cppclass Rectangle(Object):
    ...
    ... implement object get/setColor()

cdef cppclass Circle(Object):
    ...
    ... implement object get/setColor()

Because in reality, I need to split all the objects in their own pxd, pyx files. So for Object, it has blank pyx since no instance is created. When I do this, it compiles but when I use them in python, it always give me error trying to instance Object.
ImportError: dynamic module does not define module export function (PyInit_ob)

Can someone shed light on how to do it correctly?

Best,
Reply all
Reply to author
Forward
0 new messages