露出了C ++ API到Python [英] Exposing a C++ API to Python

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

问题描述

我目前工作的一个项目是我与Python来包裹C ++类要能脚本程序。所以,我的具体经验也参与到我们的节目中嵌入了Python间preTER。

I'm currently working on a project were I had to wrap the C++ classes with Python to be able to script the program. So my specific experience also involved embedding the Python interpreter in our program.

我试过的替代方案是:


  • Boost.Python的

  • Boost.Python

我喜欢用Boost.Python的产生的更简洁的API,但它会要求用户安装一个额外的依赖使我们切换到SWIG的事实。

I liked the cleaner API produced by Boost.Python, but the fact that it would have required that users install an additional dependency made us switch to SWIG.

痛饮

呷对我们的主要优点是,它不要求最终用户安装使用的最后程序

SWIG's main advantage for us was that it doesn't require end users to install it to use the final program.

你有什么用来做这个,什么已经与它的经验?

What have you used to do this, and what has been your experience with it?

推荐答案

我用两个(同一项目):升压为更好地整合与STL,特别是C ++异常。此外,它的内存管理机制(它试图弥合C ++的内存管理和Python GC)是比痛饮的更加灵活。但是,SWIG拥有的的更好的文档,没有外部的依赖关系,如果你得到包裹在夜风图书馆为Python你比中途更没有得到一个的Java /的Perl / Ruby包装器,以及

I've used both (for the same project): Boost is better integrated with the STL, and especially C++ exceptions. Also, its memory management mechanism (which tries to bridge C++ memory management and Python GC) is way more flexible than SWIG's. However, SWIG has much better documentation, no external dependencies, and if you get the library wrapped in SWIG for Python you're more than half-way there to getting a Java/Perl/Ruby wrapper as well.

我不认为有一个明确的选择:对于较小的项目,我会用Boost.Python的又来了,对于较大的长寿命的项目,SWIG额外的投资是值得的。

I don't think there's a clear-cut choice: for smaller projects, I'd go with Boost.Python again, for larger long-lived projects, the extra investment in SWIG is worth it.

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

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