Since C ++ strcut is a special definition of class, it is better to use cdef cpp class instead of cdef struct. If you use cdef struct when reading a struct that does not inherit or do anything with clang, it will not work (as of August 2015).
I don't know if I read the inherited struct because it is not written anywhere in the cython documentation.
hoge.h
typedef struct {
int moke;
double fuga;
} HogeStruct;
hoge.pxd
cdef extern from "hoge.h" nogil:
cdef struct HogeStruct:
int fuga
double piyo
hoge.pyx
def foo():
cdef HogeStruct bar
If you do this, ```elaborated type refers to a typedef `will appear in the struct HogeStruct bar in pix.
struct HogeStruct __pyx_v_bar;
`` is generated, so it conflicts with the definition statement of the struct itself.
Especially if you simply use cppclass instead of struct
hoge.h
typedef struct {
int moke;
double fuga;
} HogeStruct;
hoge.pxd
cdef extern from "hoge.h" nogil:
cdef cppclass HogeStruct:
int fuga
double piyo
hoge.pyx
def foo():
cdef HogeStruct bar
that's all.
Recommended Posts