我正在使用 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/