python绑定生成器
PyBindGen的Python项目详细描述
关于
Pybindgen是(惊喜!)python绑定生成器。主要功能有:
- Generates clean C or C++ code, nearly as readable as code written manually by a developer;
- Generated code is self contained and does not require any external libraries or macros; after generating the python module only python header files are required, nothing else;
- Does not require Boost.Python (no C++ template magic, also works in C);
- The interface for code generation is a simple Python API, not some obscure interface definition language. Additionally PyBindGen can parse header files with gccxml, if gccxml and pygccxml are installed in the system (note: pygccxml has not been ported to Python 3 yet);
- Can be easily extended with new type handlers;
- Type handlers can allocate memory and register cleanup code to free;
- Supports in, out, and inout parameters (e.g. with pointers or C++ references);
- Supports multiple return values (e.g. due to out/inout parameters);
- Supports wrapping of simple C++ classes;
- Supports virtual methods in classes;
- Supports reference counted classes and, to some extent, smart pointers;
- Multiple inheritance;
- Wrapping templated classes;
未实现的显著功能:
- Converting exceptions from Python to C++ (only from C++ to Python is currently supported);
- Callbacks.
支持的Python版本
请参阅documentation。
安装
注意:如果从Bazaar签出Pybindgen,不要忘记查看 其他指令的文件黑客攻击。
在继续之前,请确保满足系统要求。PyBindGen需要:
- Python (http://www.python.org)
- Python development files (the python-dev package in Ubuntu/Debian, for example)
- A C/C++ Compilation tool-chain (apt-get install build-essential)
- (optional) GCCXML and PyGCCXML
您可以使用setup.py或waf安装pybindgen。注:至 能够运行所有涉及代码生成的测试,以及 随后的编译,您需要使用waf。
使用setup.py安装:
python setup.py install
使用waf
安装pybindgen使用WAF作为主构建系统。 但是,waf不必预先安装,因为它是 与pybindgen一起在一个waf脚本中提供。
要安装pybindgen,请发出以下命令(win32用户应在命令中省略./prefix):
/waf配置 -也可以添加选项–prefix/foo/bar。要选择非破坏性的python版本,请使用python环境变量,例如:
PYTHON=/usr/bin/python2.4 ./waf configure
- /waf
- 可能的选项:-jn用于并行构建,-p用于进度条
- /waf检查
- 可选步骤,运行单元测试
- /waf–示例
- 可选步骤,编译示例
- /waf安装
- 可能需要sudo
Windows特定说明
waf并发错误
waf自动检测核心数并尝试激活 相应地有多个生成线程。但是,这种并发支持 在Windows上似乎有错误,因此应使用 -j1选项,如果您有多个CPU:
waf check -j1
编译器选择
注意,如果在win32上编译,waf将查找msvc (微软Visual C)默认情况下放弃寻找C/C++ 如果找不到编译器。如果您没有安装msvc,但是 如果有mingw或cygwin gcc,您必须告诉waf在 配置阶段:
waf configure –check-c-compiler=gcc –check-cxx-compiler=g++
安装
在win32上,waf install默认安装到临时文件夹。拥有 它为特定的python版本安装,使用–prefix选项 WAF配置。例如:
waf configure –prefix C:Python26 waf install
安装故障保护
如果你在华夫身上有任何问题 安装pybindGen,您应该知道pybindGen完全 自包含在pybindgen目录中。你可以简单地 递归地将整个pybindGen文件夹复制到python的 网站包目录,就这样!pybindgen是一种纯python 包并实际上不需要C/C++编译器;C++编译器只是 用于代码生成单元测试和编译示例模块,不需要生成代码。
文档
提供以下文档:
- API docs (with introductory tutorial)
- Many simple examples in the examples directory
- Advanced examples in the unit tests (tests/)
- The source code!