[SciPy-user] [Nipy-devel] how to wrap C++

Albert Strasheim fullung at gmail.com
Mon Jan 29 16:20:30 CST 2007


Hello all

On Sun, 28 Jan 2007, Stefan van der Walt wrote:

> On Sat, Jan 27, 2007 at 05:21:27PM -0600, Robert Kern wrote:
> > Stefan van der Walt wrote:
> > 
> > > Why do you specifically have to build a non-Python .so?  Ctypes
> > > doesn't seem to mind.
> > 
> > Not on your platform, perhaps. Windows does have a problem building a
> > non-extension as an extension.
> 
> I should ask Albert what he did with scipy.sandbox.svm.  I see he
> plays it safe with *3* different methods of building:
> 
> svm/setup.py
> svm/libsvm-2.82/Makefile.win
> svm/libsvm-2.82/SConstruct

Development of my libsvm wrapper went like this:

0. Got it building on Windows with Visual Studio.

1. Got it building on Windows using nmake (Makefile.win)

2. Got it building on Windows and Linux using SCons.

3. Got it building on most platforms (I ho;e) using distutils by hacking 
the following bit of cruft into the libsvm sources to make the linker 
happy on Windows:

LIBSVM_API void initlibsvm_(){}

The reason this is needed is that distutils passes an explicit /EXPORT 
argument to the Microsoft linker to export the init<modulename>_ symbol. 
Don't think there's an option to turn this off without hacking into 
distutils at a low level.

The various bits of magic needed to build a proper DLL on Windows can be 
seen at the top of this file:

http://projects.scipy.org/scipy/scipy/browser/trunk/Lib/sandbox/svm/libsvm-2.82/svm.h

with some defines and stuff in setup.py:

http://projects.scipy.org/scipy/scipy/browser/trunk/Lib/sandbox/svm/setup.py

I don't know if the "empty init" hack makes distutils's Python module 
builder a viable shared library builder on all platforms, but it works 
on Linux and Windows at least. Feels like a hack though. Probably 
because it is...

> Looking at things from the other side, he also pointed me to this url
> the other day, showing how to do build Python extensions in scons
> 
> http://www.scons.org/wiki/PythonExtensions
> 
> Something to keep in mind.

Indeed.

Cheers,

Albert


More information about the SciPy-user mailing list