[Distutils] linking with libm

Oscar Benjamin oscar.benjamin at bristol.ac.uk
Wed Nov 23 12:48:36 CET 2011


Hello,

I have an extension module that uses math.h. In order to compile it on
Linux with gcc, it needs to link with libm. However, using
libraries=['m'] leads to a linker error when using mingw32 on Windows.

At the moment my setup.py contains something like:

libraries = []
if not 'win' in sys.platform:
    libraries.append('m')

This works for the two cases I user personally.  I'm guessing, though,
that I should really be checking for something more specific, perhaps to
do with the compiler that is being used. I guess that using math.h and
wanting cross-platform compilation is probably quite a common case. So I
wondered if anyone who knows more than me about c-compilers and
distutils has a better suggestion for this.

Apologies if this is mentioned somewhere already. The only thing I could
find in the docs was instructions for adding linker options when
installing python modules. Ideally, I'd like to be able to handle this
in my setup.py without needing the setup.py user to manually alter the
linker settings.

Thanks,
Oscar.


More information about the Distutils-SIG mailing list