[英]"not a type identifier" error in Cython
我是 Cython 的新手,我正在嘗試讓一個測試項目工作,該項目從 Python 調用 C 函數:
測試.cpp :
void testFn(int arr[]);
void testFn(int arr[])
{
arr[0] = 1;
arr[1] = 2;
}
來電者.pyx :
cdef extern from "test.cpp":
void testFn(int arr[])
cpdef myTest(*arr):
testFn(arr)
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”就可以解決問題:
def myTest(int[:] arr):
testFn(&arr[0])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.