generic way to access C++ libs?

Alex Martelli aleaxit at
Mon Nov 8 13:01:40 CET 2004

Jacek Generowicz <jacek.generowicz at> wrote:
> > > > Is there any generic way to use C++ libraries from within Python.
> > > 
> > > > Without doing anything else (such as recompiling the library or
> > > > generating wrappers).
> > > 
> > > Bit of a tall order, don't you think?
> > 
> > Well, ctypes does that for C libraries (as long as they're
> > DLL/so/dynlib/...), it's not immediately obvious that using C++
> > libraries is an order of magnitude harder (though probably true).
> Maybe not _immediately_ obvious, but obvious after a few minutes
> thought :-)

To somebody with a good grasp of the current state of C++ technology,
maybe.  Somebody who might just like to using existing dynlib/&c which
happen to be oriented to C++ rather than C might quite reasonably not
find the distinction obvious, IMHO.

Indeed, I suspect ctypes could be extended to do some of the requested
task, if one focused on a single, specific C++ compiler.

> > > What would be so cumbersome about invoking a single program which
> > > requires the location of the library, the location of its headers, and
> > > which gives you a Python module wrapping the library in return ?
> > 
> > Without a C/C++ compiler around, you mean?  Most Python users these days
> > don't have one (as they use Python on Windows)...
> Good point. I hadn't though of this one. In my environment the users
> are expected to have at least one C++ compiler, and are even expected
> to use it on a regular basis.

Ah, yes, a definitely atypical environment.  Anyway, if my guess is
correct that the demand for such a 'c++types' is really burning only on
Windows, then maybe it could be made for MS VC++7.1 specifically.  But,
it IS just a guess.  ctypes does require some understanding of some C
concepts, for example, even though it does not require access to a C
compiler; it also requires specific coding to a certain dynlib's
interfaces.  I think Boost Python, if all needed tools were present,
might be able to do a more automatic job of producing the wrapper, maybe
requiring from the Python-level user even less C++ knowledge than that
hypothetical c++types might...


More information about the Python-list mailing list