I’m a Python guy building a Linux-based web service for a client who wants me to interface with a small C++ library that they’re currently using with a bunch of Windows based VB applications.
They have assured me that the library is fairly simple (as far as they go I guess), and that they just need to know how best to compile and deliver it to me so that I can use it in Python under Linux.
I’ve read a bit about the ctypes library and other options (SWIG, etc), but for some reason I haven’t really been able to wrap my head around the concept and still don’t know how to tell them what I need.
I’m pretty sure having them re-write it with Python.h, etc is out, so I’m hoping there’s a way I can simply have them compile it on Linux as a .so and just import it into Python. Is such a thing possible? How does one accomplish this?
No, such a thing is not possible.
Either they have to provide Python bindings, or you do. Either one of you can do this in any of the following ways:
<Python.h>directly to write a C extension module.boost::pythonto make writing the extension module much easier (especially when they’re using C++ rather than C).Cythonto write the extension module in a Python-like language, instead of in C or C++.ctypesfrom within Python.For very simple cases (especially if they’re actually exporting a C interface to their C++ code),
ctypesprobably is the easiest solution. Otherwise, I’d suggest looking at Cython first. But at any rate, you’re going to have to wrap your head around one of the solutions—or convince them to do it instead.