[Numpy-discussion] [f2py] How to specify compile options in setup.py

Pearu Peterson pearu.peterson@gmail....
Tue Aug 16 15:51:24 CDT 2011


On Tue, Aug 16, 2011 at 7:50 PM, Jose Gomez-Dans <jgomezdans@gmail.com>wrote:

> Hi,
> Up to now, I have managed to build Fortran extensions with f2py by ussing
> the following command:
> $ python setup.py config_fc --fcompiler=gnu95
>  --f77flags='-fmy_flags' --f90flags='-fmy_flags' build
> I think that these options should be able to go in a setup.py file, and use
> the f2py_options file. One way of doing this is to extend sys.argv with the
> required command line options:
> import sys
> sys.argv.extend ( ['config_fc', '--fcompiler=gnu95',
>  '--f77flags="-fmy_flags"', "--f90flags='-fmy_flags"] )
> This works well if all the extensions require the same flags. In my case,
> however, One of the extensions requires a different set of flags (in
> particular, it requires that flag  -fdefault-real-8 isn't set, which is
> required by the extensions). I tried setting the f2py_options in the
> add_extension method call:
> config.add_extension( 'my_extension', sources = my_sources,
>  f2py_options=['f77flags="-ffixed-line-length-0" -fdefault-real-8',
> 'f90flags="-fdefault-real-8"']  )
> This compiles the extensions (using the two dashes in front of the f2py
> option eg --f77flags results in an unrecognised option), but the f2p_options
> goes unheeded. Here's the relevant bit of the output from python setup.py
> build:
> compiling Fortran sources
> Fortran f77 compiler: /usr/bin/gfortran -ffixed-line-length-0 -fPIC -O3
> -march=native
> Fortran f90 compiler: /usr/bin/gfortran -ffixed-line-length-0 -fPIC -O3
> -march=native
> Fortran fix compiler: /usr/bin/gfortran -Wall -ffixed-form
> -fno-second-underscore -ffixed-line-length-0 -fPIC -O3 -march=native
> compile options: '-Ibuild/src.linux-i686-2.7
> -I/usr/lib/pymodules/python2.7/numpy/core/include -I/usr/include/python2.7
> -c'
> extra options: '-Jbuild/temp.linux-i686-2.7/my_dir
> -Ibuild/temp.linux-i686-2.7/my_dir'
> How can I disable (or enable) one option for compiling one particular
> extension?
You cannot do it unless you update numpy from git repo.
I just implemented the support for extra_f77_compile_args and
options that can be used in config.add_extension as well as in

So, with recent numpy the following will work

config.add_extension( 'my_extension', sources = my_sources,
                                    extra_f77_compile_args =
["-ffixed-line-length-0", "-fdefault-real-8"],
                                    extra_f90_compile_args =

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110816/3b2113ea/attachment.html 

More information about the NumPy-Discussion mailing list