c - 如何在cython中处理C typedef?

标签 c cython typedef

我正在使用 Cuba 库,我希望在我的 Cython 文件中使用 C 代码。要使用头文件 cuba.h 中我想要的方法,我在 Cython 文件的顶部编写

cdef extern from "cuba.h":
    void Cuhre(const int ndim, const int ncomp, integrand_t integrand,
    const double epsrel, const double epsabs,
    const int flags, const int mineval, const int maxeval,
    const int key,
    int *nregions, int *neval, int *fail,
    double integral[], double error[], double prob[])

Cuhre 是我唯一想使用的方法,上面是它的签名。该程序能够找到 cuba.h,但会引发错误,指出它无法将 integrand_t 识别为类型。在cuba.h中,它定义了一个函数类型*integrand_t:

typedef double cubareal;
typedef int (*integrand_t)(const int *ndim, const cubareal x[], const int *ncomp, cubareal f[], void *userdata);

那么,如何修复此错误并在我的 Cython 程序中使用 Cuba 库?预先感谢您的帮助。

最佳答案

在 cython 文件中定义 typedef,如下所示

cdef extern from "cuba.h":
    ctypedef int (*integrand_t)(const int *ndim, const cubareal x[], const int *ncomp, cubareal f[], void *userdata)

关于c - 如何在cython中处理C typedef?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49354449/

相关文章:

python - Cython 可以编译成 EXE 吗?

objective-c - 分解 objective-c 中的 typedef 结构

c - 如何打印缓冲区中的数据,无论之间是否有零,直到给定长度

python - 加速 Cython 实现点积乘法

c - sprintf 导致未定义的行为

python - 通过 Cython(回调)将 Python 函数应用于 std::vector

c - 无法定义枚举

c++ - typedef 和模板的 undefined symbol ?

缺少函数定义的 C 编译

c++ - 在 C 中使用 char 作为数组索引?