[Numpy-discussion] compile fortran from python

Pearu Peterson pearu.peterson@gmail....
Mon Oct 11 01:43:26 CDT 2010


You can create a setup.py file containing

def configuration(parent_package='',top_path=None):
     from numpy.distutils.misc_util import Configuration
     config = Configuration(None,parent_package,top_path)
     config.add_library('flib', sources = [test.f95])
     config.add_extension('ctest', sources = ['ctest.c'], 
     return config

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



   python setup.py config_fc --fcompiler=gnu95 build

will build a Fortran library flib.a and link it to
an extension module ctest.so. Use build_ext --inplace
if ctest.so should end up in current working directory.

Is that what you wanted to achieve?


On 10/09/2010 02:18 PM, Ioan Ferencik wrote:
> I would like to compile some Fortran  code using python,  build a
> shared library, and link to it using python. But I get a message
> saying the compiler does not recognise the extension of my file.
> this is my command:
> gcc -fPIC -c -shared -fno-underscoring test.f95 -o ./lib/libctest.so.1.0
> what is the easiest method to achieve this?
>    I suspect  I could create a custom extension and customise the
> unixccompiler object or could I just use the compiler object defined
> by f2py(fcompiler).
> Cheers
> Ioan Ferencik
> PhD student
> Aalto University
> School of Science and Technology
> Faculty Of Civil and Env. Engineering
> Lahti Center
> Tel: +358505122707
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

More information about the NumPy-Discussion mailing list