0

I have developped Fortran's routines that I have integrated in my Python code. So I use numpy.distutils with the following setup.py:

#!/usr/bin/env python
def configuration(parent_package='', top_path=None):
    from numpy.distutils.misc_util import Configuration
    config = Configuration('name', parent_package, top_path)
    src = ['dir1/dir2/a.f90']
    config.add_library('libname', sources=src,
                       extra_f90_compile_args=['-O3','-ffast-math','-funroll-loops'])
    config.add_extension(name='wrapper_name', sources=['dir1/dir2/wrapper_name.f90'],
                       extra_f90_compile_args=['-O3','-ffast-math','-funroll-loops'], l
                       libraries=['libname'])

    return config

if __name__ == "__main__":
    from numpy.distutils.core import setup
    setup(configuration=configuration)

This setup.py works well on my macOS but not on Debian

Fortran f77 compiler: /usr/bin/gfortran -Wall -g -ffixed-form -fno-second-underscore -fPIC -O3 -funroll-loops
Fortran f90 compiler: /usr/bin/gfortran -Wall -g -fno-second-underscore -fPIC -O3 -funroll-loops
Fortran fix compiler: /usr/bin/gfortran -Wall -g -ffixed-form -fno-second-underscore -Wall -g -fno-second-underscore -fPIC -O3 -funroll-loops
compile options: '-Ibuild/src.linux-x86_64-3.7/build/src.linux-x86_64-3.7/dir1/dir2 -I/YYY/anaconda3/lib/python3.7/site-packages/numpy/core/include -Ibuild/src.linux-x86_64-3.7/numpy/distutils/include -I/YYY/anaconda3/include/python3.7m -c'
extra options: '-Jbuild/temp.linux-x86_64-3.7/dir1/dir2 -Ibuild/temp.linux-x86_64-3.7/dir1/dir2'
gfortran:f90: dir1/dir2/wrapper_name.f90
dir1/dir2/wrapper_name.f90:872:8:

     use a, only : RR
        1
Fatal Error: Can't open module file a.mod’ for reading at (1): Aucun fichier ou dossier de ce type
compilation terminated.
error: Command "/usr/bin/gfortran -Wall -g -fno-second-underscore -fPIC -O3 -funroll-loops -Ibuild/src.linux-x86_64-3.7/build/src.linux-x86_64-3.7/dir1/dir2 -I/YYY/anaconda3/lib/python3.7/site-packages/numpy/core/include -Ibuild/src.linux-x86_64-3.7/numpy/distutils/include -I/YYY/anaconda3/include/python3.7m -c -c dir1/dir2/wrapper_name.f90 -o build/temp.linux-x86_64-3.7/dir1/dir2/wrapper_name.o -Jbuild/temp.linux-x86_64-3.7/dir1/dir2 -Ibuild/temp.linux-x86_64-3.7/dir1/dir2" failed with exit status 1

The missing .mod seems to not be at the right place but I don't understand why it is working on macOS and not working in Debian.

Guuk
  • 505
  • 3
  • 17
  • Is there some kind of verbose option to `setup.py` which would show how the file containing `module a` is compiled? It's possible that `a.mod` is being made in an unexpected directory. Alternatively, dependencies might not have been specified correctly, so that `module a` is (sometimes) compiled after `wrapper_name.f90`. – veryreverie Mar 10 '22 at 09:12
  • I just look at this and I notice that `a.mod` is in `./build/temp.linux-x86_64-3.7/` which is not included in the command to compile `wrapper_name.f90`. – Guuk Mar 10 '22 at 13:39
  • The easiest solution is probably to put all `.mod` files in one directory. See [Specify directory where gfortran should look for modules](https://stackoverflow.com/questions/8855896/specify-directory-where-gfortran-should-look-for-modules) for details. – veryreverie Mar 10 '22 at 14:07
  • It is a good solution if I use directly `gfortran` but calls of gfortran are here managed by `distutils`. The trouble is that the building directory is automatically determined by it. – Guuk Mar 10 '22 at 14:48
  • I don't know how `disutils` works, but can you not just add the relevant flags to `extra_f90_compiler_args`? Or does `disutils` have some setting for module file location? – veryreverie Mar 10 '22 at 16:36

0 Answers0