[Numpy-discussion] f2py complications

Jose Gomez-Dans jgomezdans at gmail.com
Thu May 12 09:14:49 EDT 2011


Hi,

We have some fortran code that we'd like to wrap using f2py. The code
consists of a library that we compile into an .so file, and a file that
wraps that library, which is then wrapped by f2py to provide a clean
interface to the library. The process thus includes two steps:
1.- Use a makefile to compile the library
2.- Use f2py to create the python bindings from a fortran file, and link
dynamically to the library created in the previous step.

Now, I don't see why just a call to f2py shouldn't suffice (we don't really
need to have an .so lying around, and it implies that we have to set eg
$LD_LIBRARY_PATH to search for it). I thought about using a pyf file for
this, and use the only :: option:
$ f2py -h my_model.pyf -m my_model  my_wrapper.f90 only: func1 func2 func3 :
all_my_other_files.f even_more_files.f90
$ f2py -c  -m my_model  --f90flags="-fdefault-real-8 -O3 -march=native -m32"
--f90exec=/usr/bin/gfortran  --f77exec=/usr/bin/gfortran --opt=-O3
 my_model.pyf

This however, doesn't seem to work, with python complaining about missing
things. If I put all my *.f and *f90 files after the my_model.pyf (which
doesn't seem to have them in the file), I get undefined symbol errors when
importing the .so in python.

Additionally, it would be great to have this compilation in a
distutils-friendly package, but how do you specify all these compiler flags?

Thanks!
Jose
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110512/fe015d27/attachment.html>


More information about the NumPy-Discussion mailing list