将C ++头文件转换为Python [英] Convert C++ Header Files To Python
问题描述
我不知道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屋!