无法使用 gccxml 的 pybindgen



我有一个C++库,我想绑定到Python。我开始使用 Pybindgen,它真的很容易使用,但考虑到我的C++库的大小,手动添加函数和命名空间将花费很长时间。我已经通读了有关PyBindGen的文档,特别是gccxml部分,据说它为我扫描头文件。这将是理想的,但我无法让它正常运行。作为测试,我输入了我的主头文件并尝试导出它,但我收到此错误:

python bindinggenerator.py
Traceback (most recent call last):
  File "bindinggenerator.py", line 16, in <module>
    main()
  File "bindinggenerator.py", line 9, in main
    module = module_parser.parse("include\PhospheneEngine.h")
  File "C:UserspaoloAppDataLocalProgramsPythonPython35-32libsite-packagespybindgengccxmlparser.py", line 598, in parse
    pygen_classifier, gccxml_options)
  File "C:UserspaoloAppDataLocalProgramsPythonPython35-32libsite-packagespybindgengccxmlparser.py", line 658, in parse_init
    assert isinstance(header_files, list)
AssertionError

当然,我的Python代码基本上只是这里修改后的示例。

import sys
import pybindgen
from pybindgen import FileCodeSink
from pybindgen.gccxmlparser import ModuleParser
def main():
    module_parser = ModuleParser('PhospheneEngine', '::')
    module = module_parser.parse("include\PhospheneEngine.h")
    module.add_include("'include\PhospheneEngine.h'")
    pybindgen.write_preamble(FileCodeSink(sys.stdout))
    module.generate(FileCodeSink(sys.stdout))
if (__name__ == '__main__'):
    main()

我已经安装了gccxml和pygccxml(对于Python 3.5)。文档实际上并没有对此过程进行太多说明,因此可能会简要介绍如何使用此功能。

提前谢谢。

parse 函数采用标头列表。

module = module_parser.parse(["include\PhospheneEngine.h"])

最新更新