我是Cython的新手,我试图让一个从Python调用C函数的测试项目正常工作:
测试.cpp:
void testFn(int arr[]);
void testFn(int arr[])
{
arr[0] = 1;
arr[1] = 2;
}
呼叫者.pyx:
^{pr2}$setup.caller.py:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
sourcefiles = ['caller.pyx']
ext_modules = [Extension("caller", sourcefiles)]
setup(
name = 'test app',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules
)
但当我试图构建项目时,我得到了一个错误:
$ python setup.caller.py build_ext --inplace
running build_ext
cythoning caller.pyx to caller.c
Error compiling Cython file:
------------------------------------------------------------
...
cdef extern from "test.cpp":
void testFn(int arr[])
cpdef myTest(*arr):
^
------------------------------------------------------------
caller.pyx:4:6: 'myTest' is not a type identifier
在我的例子中,第二个定义不需要“cpdef”或“cdef”,通常的“def”起了作用:
相关问题 更多 >
编程相关推荐