[SciPy-User] Wrapping C/C++ Code

Sebastian Walter sebastian.walter@gmail....
Wed Nov 4 04:05:52 CST 2009


1)
I'd also use ctypes whenever possible. Numpy offers good builtin
support to make it easy to call
C/Fortran functions that expect pointers to arrays. There is a nice tutorial on
http://www.scipy.org/Cookbook/Ctypes

Unfortunately, this route only works for C  and not for C++, so you
would have to write a C interface to a C++ library.

2) I use boost::python to wrap existing C++ projects in a quite
verbose way, e.g.  in
http://github.com/b45ch1/pyadolc/blob/master/adolc/src/py_adolc.hpp

It works reasonably well when you know what you are doing and it's
also quite flexible.
The downside is  the documentation, the long compilation times and the
"magic" template implementation
that is hard to understand.

hope that helps a little,
Sebastian


On Tue, Nov 3, 2009 at 5:25 PM, Zachary Pincus <zachary.pincus@yale.edu> wrote:
> Another option instead of SWIG, if you have a reasonably stable C API
> and a pre-built shared library exporting the same, is to use ctypes to
> call into it. This works well enough with many numeric APIs, too where
> you can allocate arrays with numpy, and then use the array's ctypes
> attribute to get at a pointer to the memory suitable for passing into
> the C code.
>
> The downside is that (as far as I know) there's no good way to build
> pure-C libraries as part of a "python setup.py build" step (though
> some functionality along these lines might be now in the numpy
> distutuls?).
>
> Zach
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>


More information about the SciPy-User mailing list