将C ++头文件转换为Python

时间:2022-04-10 15:07:22

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.

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

4 个解决方案

#1


11  

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.

我不知道h2py,但你可能想看看'ctypes'和'ctypeslib'。 ctypes包含在python 2.5+中,旨在创建与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,你会得到一个名为codegen的子工具,它有一个'h2xml.py'脚本和一个'xml2py.py',它们的组合将自动生成你正在寻找C ++的python代码头。

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

h2xml.py将需要另一个名为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.

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

#2


3  

Just found pycparser. May be useful.

刚发现pycparser。可能有用。

#3


1  

From what I can tell, h2py.py isn't intended to convert anything other than #define macros. I did run across cppheaderparser, which might be worth a look.

据我所知,h2py.py不打算转换#define宏以外的任何东西。我确实遇到了cppheaderparser,这可能值得一看。

#4


-1  

Where did you get the idea that h2py had anything to do with structs or enums?

你在哪里知道h2py与结构或枚举有什么关系?

From the source

来自消息来源

# Read #define's and translate to Python code.
# Handle #include statements.
# Handle #define macros with one argument.

The words 'enum' and 'struct' never appear in the module.

单词'enum'和'struct'永远不会出现在模块中。

#1


11  

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.

我不知道h2py,但你可能想看看'ctypes'和'ctypeslib'。 ctypes包含在python 2.5+中,旨在创建与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,你会得到一个名为codegen的子工具,它有一个'h2xml.py'脚本和一个'xml2py.py',它们的组合将自动生成你正在寻找C ++的python代码头。

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

h2xml.py将需要另一个名为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.

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

#2


3  

Just found pycparser. May be useful.

刚发现pycparser。可能有用。

#3


1  

From what I can tell, h2py.py isn't intended to convert anything other than #define macros. I did run across cppheaderparser, which might be worth a look.

据我所知,h2py.py不打算转换#define宏以外的任何东西。我确实遇到了cppheaderparser,这可能值得一看。

#4


-1  

Where did you get the idea that h2py had anything to do with structs or enums?

你在哪里知道h2py与结构或枚举有什么关系?

From the source

来自消息来源

# Read #define's and translate to Python code.
# Handle #include statements.
# Handle #define macros with one argument.

The words 'enum' and 'struct' never appear in the module.

单词'enum'和'struct'永远不会出现在模块中。