Exposing a C++ API to Python

前端 未结 5 1338
夕颜
夕颜 2020-12-07 14:20

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 Py

5条回答
  •  一个人的身影
    2020-12-07 14:45

    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.

    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.

提交回复
热议问题