[SciPy-dev] Re: build_flib.py again

Pearu Peterson pearu at scipy.org
Wed Oct 29 14:38:47 CST 2003

On Wed, 29 Oct 2003, [iso-8859-15] Berthold Höllmann wrote:

> Pearu Peterson <pearu at scipy.org> writes:
> > Could you give a more detailed example of the fortran wrapper and how do 
> > you wrap it to Python? If these wrappers can be modified e.g. by inserting 
> > f2py directives, then `fortranname` .pyf file command might be what you 
> > need.
> Now i have a binary Fortran library named 'provided'. 'provided'
> provides a function 'subroutine foo()' which leads to a symol '_FOO at 0'
> in the library. Now i want to write a function that makes intensive
> use of 'foo', so I write a Fortran routine 'subroutine usefoo()' that
> is specific to python ant I wrap it unsing f2py. Because 'usefoo' is
> only usefull for my Python extension library I include it's sourcecode
> in my Python Project and build it as 'fortran_libraries' using scipy
> distutils. With the switches' settings as they are now this does not
> work, because the linker looks for '_foo_' instead of '_FOO' or
> '_FOO at 0'.

Thanks for the explanation. So, you must be also using -DUPPERCASE_FORTRAN
and -DPREPEND_FORTRAN cpp options. In fact, there are two possible ways
for resolving Fortran symbols in f2py generated modules:
+ One is to uses compiler options to force certian convention that I 
explained earlier.
+ And the other is to use certain combinations of the CPP variables 

In scipy_distutils we are using the first way because of two reasons: 
(i) this avoids issues with symbols containing characters like @ or ! 
that certain Fortran compilers may add to the initial names; namely, these 
characters in names will cause C compiler to complain as they are not 
allowed characters for C names.
(ii) we haven't worked out a way how to define CPP macros for a C compiler 
depending on the Fortran compiler, and all that within the framework of 

But to resolve your case, there should be a way to define Fortran compiler 
options for scipy_distutils, but this feature is not implemented yet 
because we haven't needed it earlier. Meanwhile, you can use the following 
workaround in the setup.py file:

from scipy_distutils.command import build_flib
class my_fortran_compiler(build_flib.compaq_visual_fortran_compiler):
 def __init__(self, fc=None, f90c=None, verbose=0):
   s = self.f77_switches
   s = s.replace('/names:lowercase','')
   s = s.replace('/assume:underscore','')
   # ...
   self.f77_switches = s
   # similarly can be self.f90_switches fixed.

i = build_flib.all_compilers.index(build_flib.compaq_visual_fortran_compiler)
build_flib.all_compilers[i] = my_fortran_compiler

Note that I have not tested this code but it should work after fixing any 
possible typos that I might have been made here.


More information about the Scipy-dev mailing list