[SciPy-dev] Re: Another issue with scipy_distutils and FORTRAN files

Pearu Peterson pearu at scipy.org
Tue Mar 30 10:33:13 CST 2004


Hi Berthold,

On Tue, 30 Mar 2004, [ISO-8859-15] Berthold Höllmann wrote:

> It turned out, the problem is how to tell include directiories when
> generating a library. We use
> 
> ---snip---
> ...
> flibs = [('fortmisc',
>           {'sources': lib_src,
>            'include_dirs': [os.path.join("lib", "numfort")],
>            'macros':[]},),]
> ...
> setup(...
>       libraries=flibs,
>       ...)
> ...
> ---snip---

This usage of specifying libraries is not recommended and some of the
corresponding features were removed indentionally (but at the moment I am
not sure why the above does not work..), though the standard distutils
might support this. The reason comes from the experience of building 
scipy: the above approach would cause 'fortmisc' to be linked with 
all extension modules that a package contains and this may cause undesired 
effects, for example, when subpackages define different libriaries 
with the same name, etc. The recommended way of specifying libriaries is 
to add them explicitely to extension modules that actually need them:

  flibs = [('fortmisc', {'sources': ..., 'include_dirs': ...})]

  ext = Extension('extname',
                   ...
                   libraires = [..]+flibs,
                   ...)

  setup(...,
        ext_modules = [ext,..],
        ...)

> I guess the the correct fix lies in _compiler in fcompiler.py. The line
> 
> ---snip---
>         command = compiler + cc_args + s_args + o_args + extra_postargs
> ---snip---
> 
> should be
> 
> ---snip---
>         command = compiler + cc_args + s_args + o_args + extra_postargs + pp_opts
> ---snip---
> 
> (at least this works for me). 

Let me know if the above approach of specifying libraires is acceptable 
for your application and then I'll postpone tracking down the "correct" 
fix to the problem. I am just hesitating commiting patches that I don't 
understand fully.. pp_opts should probably used only as preprocessor 
arguments but scipy_distutils does not have preprocessor support yet.

> Of course "NB.F" only compiles with
> another (helpfull) patch to fcompiler.f. I changed 
> 
> ---snip---
>     language_map = {'.f':'f77',
>                     '.for':'f77',
>                     '.F':'f77',
>                     '.ftn':'f77',
>                     '.f77':'f77',
>                     '.f90':'f90',
>                     '.F90':'f90',
>                     '.f95':'f90'}
> ---snip---
> 
> and
> 
> ---snip---
>     src_extensions = ['.for','.ftn','.f77','.f','.f90','.f95','.F','.F90']
> ---snip---

This is now in CVS.

> Probably 'language_map' shold reflect that '.F' and '.F90' files
> should be preprocessed using fpp, and fpp must be explicitly switche
> on on some platforms.

Yes, I agree.

Thanks,
Pearu




More information about the Scipy-dev mailing list