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

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

问题描述

我有一个包含#define语句,枚举和结构的C ++头文件。我已经尝试使用Python附带的h2py.py脚本无效(除了给我#define转换)。任何帮助将不胜感激。

解决方案

我不知道h2py,但你可能想看看'ctypes'和'ctypeslib'。 ctypes包含在python 2.5+中,目标是创建与c-structs的二进制兼容性。



如果添加ctypeslib,您将得到一个名为codegen的子工具,有一个'h2xml.py'脚本和一个'xml2py.py',其组合将自动生成您正在从C ++头文件中寻找的python代码。



ctypeslib: http://pypi.python.org/pypi/ctypeslib/0.5。 4a



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



最好退房(通过CVS )最新版本的gccxml并自己构建(实际上比说简单)。预包装版本较旧。


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.

解决方案

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.

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

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

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天全站免登陆