[Tutor] c++ on python

Russel Winder russel at winder.org.uk
Thu Mar 13 12:36:47 CET 2014


On Wed, 2014-03-12 at 22:05 +0000, Alan Gauld wrote:
> On 12/03/14 16:49, Stefan Behnel wrote:
> > Alan Gauld, 12.03.2014 10:11:
> >> If it were a library then you would have to call
> >> the individual C++ functions directly using
> >> something like ctypes, which is usually more
> >> complex.
> >
> > ctypes won't talk to C++, but Cython can do it quite easily.
> 
> I thought it would work provided the interface functions
> were declared as C functions? That might involve
> writing a wrapper around it but that is usually
> trivial if you have to compile the source anyway.

ctypes (and CFFI) talks quite happily to C++ functions as long as they
are declared with C linkage (so as to avoid any "name mangling"):

        export "C" x f(…){…}

makes f accessible via ctypes if f is in a shared object/dynamic link
library.

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/tutor/attachments/20140313/71fc1b39/attachment.sig>


More information about the Tutor mailing list