Reputation: 61
I am trying to wrap a c++ library using cython. The c++ header file say MyFile.h declares a class like this:
class MyClass {
public:
enum MyEnum{
TYPE0 = 0,
TYPE1 = 1,
TYPE2 = 2,
};
MyClass(MyEnum val=TYPE0){
// ...
}
// ...
}
The pxd file has this:
cdef extern from "<MyFile.h>":
cdef cppclass MyClass:
cdef enum MyEnum:
TYPE0 = 0
TYPE1 = 1
TYPE2 = 2
MyClass(MyEnum val=TYPE0) except +
But cython does not compile it. How do I do this?
Upvotes: 3
Views: 1037
Reputation: 20675
Try using namespace:
cdef extern from "MyFile.h" namespace "MyClass":
cdef enum MyEnum:
TYPE0 = 0
TYPE1 = 1
TYPE2 = 2
Or maybe this will work as well:
cdef extern from "MyFile.h":
cdef enum MyEnum "MyClass::MyEnum":
TYPE0 = 0
...
Upvotes: 4