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