Building Quantlib Python bindings (32bit) on MacOSX

December 30, 2010

I needed to use Quantlib with Traits on MacOSX. As the Traits backends are not available in 64bit on MacOSX with EPD, I had to build a 32bit version of Quantlib and the related swig bindings to make it work. By default, Quantlib will be built in 64bit mode and you will get the following warning when building the Python swig bindings using a 32bit Python installation (python setup.py build):

ld: warning: in /opt/local/lib/libQuantLib.dylib, file was built for unsupported file format which is not the architecture being linked (i386)

and the following error when trying to run the test (python setup.py test)

ImportError: dlopen(build/lib.macosx-10.5-i386-2.6/QuantLib/_QuantLib.so, 2): Symbol not found: __ZN8QuantLib12SmileSection6updateEv
Referenced from: /Users/dpinte/Downloads/QuantLib-SWIG-1.0/Python/build/lib.macosx-10.5-i386-2.6/QuantLib/_QuantLib.so
Expected in: flat namespace
in /Users/dpinte/Downloads/QuantLib-SWIG-1.0/Python/build/lib.macosx-10.5-i386-2.6/QuantLib/_QuantLib.so

1. Build Quantlib after making sure you do have Boost installed (you can use MacPorts for that):

export CFLAGS=-m32
export CPPFLAGS=-m32
export CXXFLAGS=-m32
./configure --enable-static --with-boost-include=/opt/local/include/ \
--with-boost-lib=/opt/local/lib/ --prefix=/opt/local/
make
make install

2. Build the swig bindings:


python setup.py build
python setup.py test
python setup.py install

And it should work fine :


...
Ran 25 tests in 0.889s

OK

Advertisements