Cython extern 函数从 foo.h 转换为类似模块的对象?
我想做以下事情:
cdef extern from "foo.h" namespace "foo":
int bar(int, int)
def bar(a, b):
return foo.bar(a, b)
但这不起作用。 命名空间“foo”
部分的作用是什么?如何实现将从“foo.h”外部的函数加载到名为 foo 的对象中?
更新:
我可以使用以下文件结构和代码找到解决方案:
spam.pyx
spam_c.pxd
c\
spam.c
# spam.pyx
cimport spam_c as spam
def foo(a, b):
return spam.foo(a, b)
# spam_c.pxd
cdef extern from "spam.c":
double foo(double, double)
有更好的方法来解决这个问题吗?
I'd like to do the following:
cdef extern from "foo.h" namespace "foo":
int bar(int, int)
def bar(a, b):
return foo.bar(a, b)
But this does not work. What is the namespace "foo"
part for ? And how can I achieve to load the functions externed from "foo.h" into an object named foo ?
Update:
I could find a solution using the following file-structure and code:
spam.pyx
spam_c.pxd
c\
spam.c
# spam.pyx
cimport spam_c as spam
def foo(a, b):
return spam.foo(a, b)
# spam_c.pxd
cdef extern from "spam.c":
double foo(double, double)
Is there a better way to solve this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现这是处理这个问题的首选方法。
I have found out that this is the preferred way to deal with this.