Calling C++ Modules in Python

Dan Stromberg drsalists at gmail.com
Fri Mar 11 17:37:55 EST 2011


I've not tried Boost, but I don't think SWIG or Cython require modified
libraries.  You just compile your wrapper, and then import it.

On Fri, Mar 11, 2011 at 2:16 PM, <zxpatric at gmail.com> wrote:

> Dan,
>
> Thanks for the info. Really I was hoping for a "non-intrusive" way to
> expose existing C++ libraries to python. However, both solutions (BOOST,
> SWIG) listed here require the recompilation of libraries?! Seems Cython is
> doing the similar way? It is ok for small applications but will be hard for
> big software from big companies. The reason is that even companies are
> willing to rebuild their own libraries with those wrappers or decorations
> added(though needs approves from all sorts of departments :)), they can't
> force their 3rd-party developers/users.
> Correct me if I am wrong.
>
> Rg,
> -Patrick
>
> On Mar 11, 2011 4:59pm, Dan Stromberg <drsalists at gmail.com> wrote:
> >
> > On Fri, Mar 11, 2011 at 1:15 PM, Patrick zxpatric at gmail.com> wrote:
> >
> >
> > Hi,
> >
> >
> >
> >
> >
> > I saw in the Beginner document that "•Is easily extended by adding new
> >
> >
> > modules implemented in a compiled language such as C or C++. ".
> >
> >
> >
> >
> >
> > While to my investigation, it seems not that easy or did I miss
> >
> >
> > something?
> >
> >
> >
> >
> >
> > boost python (C++ libraries need to be re-compiled with written
> >
> >
> > wrappers again?).
> >
> >
> > SWIG  (It works by taking the declarations found in C/C++ header and
> >
> >
> > using them to generate the wrapper code that scripting languages need
> >
> >
> > to access the underlying C/C++ code).
> >
> > I guess it should be asked: "easy for who"?  "easy" is always relative to
> some context.
> >
> > If you're planning to stay with CPython and C++ forevermore, then Cython
> is a nice way of gluing the two.   Cython looks like Python code, but it
> gives you access to C and C++ code and data as well as CPython code and
> data.
> >
> >
> >
> > If you're planning to support your C++ code with more languages than
> CPython, you might be better off with SWIG.
> >
> > If you really do want to do the task the old way, you're probably best
> off copying some preexisting module with a maximize-the-developers-rights
> license (like Apache, MIT or 3 clause BSD), and modifying that.
> >
> >
> >
> > If you want to be able to move easily to pypy, I might suggest coming up
> with a C wrapper for your C++ code, and then accessing the C code using
> ctypes.  That should work in CPython and pypy, and it looks like jython
> might support this soon as well.
> >
> >
> >
> >
> >
> >
> >
> >
> >
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110311/b92fc60b/attachment-0001.html>


More information about the Python-list mailing list