从其他 Cython 声明文件导入外部声明

Importing extern declaration from other Cython declaration file

我正在编写用于 Python 的 Cython 扩展。

我有这个 Cython 声明 .pxd 文件,它声明了一个在其他 C 头文件中定义的 C 结构:

# Cython definitions for parameters.h
cdef extern from "parameters.h":
    ctypedef struct control_par:
        int num_cams
        # some other struct fields....

现在我想对其他头文件做同样的事情,但在这里我将不得不使用我在上面定义的内容:另一个 Cython .pxd 文件中的 control_par C 结构:

from optv cimport parameters, calibration # no error here during setup
cdef extern from "optv/trafo.h":
    void pixel_to_metric(# some other parameters...
                         control_par * parameters);

在 cythonizing 期间我得到这个错误:

'control_par' is not a type identifier

好像根本没有定义。

我做错了什么?

导入 C 定义的正确方法是 parameters.control_par。我会这样做:

from optv.parameters cimport control_par, whatever_else_you_need