Hi,
I am creating Cython extension to a FORTRAN library. I do follow advice from
www.fortran90.org, that is write an interface using iso_c_binding. My issue is how to compile the code from distutils setup.py. I came up with the following solution:
In setup.py:
import build_ftn_ext # works only with gcc
def get_extensions():
if use_cython:
ext_modules = [
Extension('nceputils._funcphys',
['nceputils/_funcphys.pyx', 'nceputils/physif.f90'],
libraries=['phys', 'gfortran'],
...
where physif.f90 is my interface to library libphys.so and build_ftn_ext is a monkey patch:
import distutils.command.build_ext
# Allows gcc to compile FORTRAN code
_tmp = distutils.command.build_ext.build_ext
class build_ftn_ext(_tmp):
description = "As build_ext(), allows FORTRAN objects to be made by gcc"
def build_extensions(self):
self.compiler.src_extensions.extend(['.f90'])
for ext in self.extensions:
ext.extra_compile_args.extend(['-J', self.build_temp])
_tmp.build_extensions(self)
distutils.command.build_ext.build_ext = build_ftn_ext
This works fine for me, I do not anticipate having to switch to a different compiler. But, is there a better solution?
George