UPDATE 在GitHub上最小的例子:https://github.com/wl2776/cython_error地图数组用Cython
我有一个C库,我想从Python来访问。我正在为它开发一个Cython包装器。
图书馆有以下声明:
文件 “globals.h”
typedef struct
{
int x;
int y;
int radius;
} circleData;
文件 “O_Recognition.h”
#include "globals.h"
typedef struct
{
int obj_count;
circleData circle_data[2];
float parameters[2];
} objectData;
我在映射这些类型用Cython。 PXD文件,如下所示:
文件 “cO_Recognition.pxd”:
cdef extern from "globals.h":
ctypedef struct circleData:
int x;
int y;
int radius;
cdef extern from "O_Recognition.h":
ctypedef struct objectData:
int obj_count;
circleData circle_data[2];
float parameters[2];
而且这不会编译。我得到的错误:
Error compiling Cython file:
------------------------------------------------------------
...
void PyTuple_SET_ITEM(object p, Py_ssize_t pos, object o)
void PyList_SET_ITEM(object p, Py_ssize_t pos, object o)
@cname("__Pyx_carray_to_py_circleData")
cdef inline list __Pyx_carray_to_py_circleData(circleData *v, Py_ssize_t length):
^
------------------------------------------------------------
carray.to_py:112:45 'circleData' is not a type identifier
一个细节,这是CMake的项目的一部分,正在使用从GitHub这个例子建:https://github.com/thewtex/cython-cmake-example
的CMakeLists.txt的相关部分包括与.pyx文件其他名称,cimport
s This cDeclarations.pxd
添加一些包括警卫C头文件,我在jupyter笔记本编译了代码成功。(cython0.25.2 + vs2015) – oz1
@ OZ1,我已经添加了细节。这些声明位于.pxd文件中 – wl2776