[Numpy-discussion] Building a static libnumpy

Jussi Enkovaara jussi.enkovaara@csc...
Tue Jan 22 04:52:34 CST 2008

David Cournapeau wrote:
> On Jan 22, 2008 3:44 PM, Jussi Enkovaara <jussi.enkovaara@csc.fi> wrote:
>> Hi,
>> I need to use numpy in an environment which does not support shared libraries.
>> Previously, I have used the old Numeric where I created a Makefile to build a
>> static Numeric library which was later on linked to the python interpreter.
> Interesting, did not know it was possible. How did you do it ?
> I am working on an alternative build system for numpy, based on scons,
> and depending on the necessary steps, I could add this feature to the
> build system. scons itself certainly support static libraries, but I
> have never built static python extensions.

The tricky part is the creation of the static library, with Numeric I just put all 
the object files to a library with 'ar', e.g.

ar cr libnumpy.a $(OBJ)

When having the static library, one can specify the static modules in the file 
Modules/Setup in Python source tree. The file is well documented and contains 
detailed instructions for building static modules. In the case of Numeric, I had 
the following lines in Setup:

NUMPY = ${HOME}/Numeric-23.8/libnumpy.a
_numpy $(NUMPY)
arrayfns $(NUMPY)
ranlib $(NUMPY)
multiarray $(NUMPY)
umath $(NUMPY)
lapack_lite $(NUMPY)
fftpack $(NUMPY)

It is of course very cumbersome as one has to specify all the modules which are 
written in C before compiling the actual interpreter. I think that the whole 
procedure cannot be automatized, but it should be possible to have distutils to 
create the static library and produce maybe the lines to be included in 
Modules/Setup. Thus, one should first create a minimal interpreter, then build the 
necessary extensions statically with this minimal interpreter and distutils, and 
at the end create the full featured python interpreter.

At some point I tried to look the distutils source but I did not have the time to 
understand it properly so that I could make the necessary modifications.

Jussi Enkovaara

More information about the Numpy-discussion mailing list