On 01/23/2012 09:03 PM, Jim Bosch wrote:
On 01/23/2012 02:35 PM, Bo Jensen wrote:
Hi,

I have been looking into the best way for me to make a python wrapper for a C++ library. Boost.Python looks nice and seem to fit my needs, but I have a
few questions before I dig in deep and do the implementation.

What I want to do :

I have a very thin header only C++ library, which is an extension on top of a c library i.e some of the C++ functions call functions in a C dll/so. So
the C++ library only provides a nice way of using the C library with
operators and overloading etc. For this library I want to make an python
interface, which only should mimic the C++ classes and functions i.e there
will be a 1:1 mapping.

Questions :

1) Would Boost.Python be suited for such a task ?


Almost definitely. For this sort of task most people use Boost.Python, SWIG, or the raw Python C-API.

Boost.Python is my favorite, and probably the favorite of most people on this list. The Python C-API (what I think you're calling "cython") is a lot less automatic; you'll find yourself writing a lot more code, and doing a lot more memory management. SWIG can be much more automatic if your C/C++ interface is sufficiently simple, but it's generally less safe w.r.t. memory management, it chokes on complex C++, and I find it much more difficult to debug.

Cython is something entirely different: see http://cython.org/ . If you are basically wrapping a C library I suspect using cython is simpler and faster. If C++ support in cython is further improved it will be a serious alternative to boost.python.

Regards,
Wichert.
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to