【问题标题】:Wrapping a C function in Cython which has non-stanard types as arguments在 Cython 中包装具有非标准类型作为参数的 C 函数
【发布时间】:2018-05-30 14:42:57
【问题描述】:

我正在尝试包装一个具有 uint32_t 类型参数的 C++ 函数,该函数可以在 cstdint 库中找到。假设 C++ 文件看起来像

cppfile.cpp:

#include <cstdint>

int foo(uint32_t x){
    return 1;
}

如何将其包装在 Cython .pxd 文件中?如果 x 只是一个普通整数,我会这样做

cdef extern from "cppfile.cpp":
    cdef int foo(int x)

但是当 x 是 uint32_t 类型时,我该怎么做呢?如何获取 uint32_t 作为 cython 中的类型?

【问题讨论】:

  • 它是 C 函数还是 C++ 函数?标题说的是 C 函数,而描述则描绘了不同的画面。

标签: python c++ cython


【解决方案1】:

这是FAQ of cython回答的问题

from libc.stdint cimport uint32_t

cdef extern from "cppfile.cpp":
    cdef int foo(uint32_t x)

【讨论】:

    猜你喜欢
    • 2015-06-17
    • 2013-09-11
    • 2020-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多