Building Quantlib Python bindings (32bit) on MacOSX

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

About these ads

2 Responses to Building Quantlib Python bindings (32bit) on MacOSX

  1. sriram says:

    I followed your instructions above, as I also run Mac OS X (10.6.8). I installed boost via macports. I then downloaded the Quantlib source (1.2.1) and compiled using the directions you supplied in (1). Finally, I built the swig bindings as you gave in (2). In running python setup.py test, I get

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

    Do you have any thoughts?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: