我正在使用python文件来调用已经通过cffi翻译的C ++结构。我目前收到错误,我的结构无法调用。如何正确调用此结构?我是否首先正确地在cffi转换器中定义了结构?
(simple_cffi_builder.py)
declare var PDFjs
我要调用的结构(_simplebfs_cffi.cpp):
import os
from cffi import FFI
ffibuilder = FFI()
basePath = os.path.dirname(__file__)
filePath = os.path.abspath(os.path.join(basePath, "..", "..", "build/bin/simple_bfs.cpp"))
runtimePath = os.path.abspath(os.path.join(basePath, "..", "..", "src/runtime_lib"))
intrinsicsPath = os.path.abspath(os.path.join(basePath, "..", "..", "src/runtime_lib/intrinsics.h"))
with open(filePath,'r') as f:
ffibuilder.set_source("_simplebfs_cffi",
f.read(),
include_dirs=[runtimePath],
source_extension = ".cpp",
extra_compile_args = ["-std=c++11"]
)
ffibuilder.cdef(
"""
struct run_bfs{};
"""
)
if __name__ == "__main__":
ffibuilder.compile(verbose=True)
我用来调用生成的C ++代码的代码(run_simple_bfs_cffi_python.py):
struct run_bfs
{
void operator() ()
{
lots of code stuff
}
}
当我尝试运行上面的代码时,出现错误:
跟踪(最近一次通话最后一次):在run_bfs()()中的文件“ run_simple_bfs_cffi_python.py”,第18行,在通话(self.bfs)中的文件“ run_simple_bfs_cffi_python.py” )()TypeError:cdata'struct run_bfs *'无法调用