将C ++头文件转换为Python [英] Convert C++ Header Files To Python

查看:825
本文介绍了将C ++头文件转换为Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++头包含#define语句,枚举和结构。我试着使用Python中包含的h2py.py脚本无效(除了给我#defines转换)。任何帮助将非常感激。

I have a C++ header that contains #define statements, Enums and Structures. I have tried using the h2py.py script that is included with Python to no avail (except giving me the #defines converted). Any help would be greatly appreciated.

推荐答案

我不知道h2py,但你可能想看看'ctypes' 'ctypeslib'。

I don't know h2py, but you may want to look at 'ctypes' and 'ctypeslib'. ctypes is included with python 2.5+, and is targeted at creating binary compatibility with c-structs.

如果你添加ctypeslib,你会得到一个名为codegen的子工具,有一个'h2xml.py'脚本和一个'xml2py.py',它们的组合将自动生成你正在从C ++头找到的Python代码。

If you add ctypeslib, you get a sub-tool called codegen, which has a 'h2xml.py' script, and a 'xml2py.py', the combination of which will auto-generate the python code you're looking for from C++ headers.

ctypeslib: http://pypi.python.org/pypi/ctypeslib/0.5.4a

ctypeslib:http://pypi.python.org/pypi/ctypeslib/0.5.4a

h2xml.py需要使用另一个名为gccxml的工具: http://www.gccxml.org/HTML/Index.html

h2xml.py will require another tool called gccxml: http://www.gccxml.org/HTML/Index.html

最好检查(通过CVS)最新版本的gccxml并自己构建(实际上比说更容易做)。预打包的版本是旧的。

it's best to check out (via CVS) the latest version of gccxml and build it yourself (actually easier done than said). The pre-packaged version is old.

这篇关于将C ++头文件转换为Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆