F2py Giving "redefinition Of 'foo'... Previous Definition Was Here"
Solution 1:
One solution would be to create a module erf.f90
and import it in your main code using use erf
(or whatever it's name is).
I have had some strange problems with f2py
importing modules named with a .f
extension, you might be able to get it to work simply by renaming erf.f
to erf.f90
and specifying -ffixed-form
when you compile with gfortran
.
EDIT:
If you import the module using use
, you do not need to also use include
. include
is basically including the actual code of erf.f
in the source of your main code (although as you noticed, it doesn't behave exactly the same as typing erf.f
directly into the main file), while use
tells the compiler to look for a pre-compiled module.
I have found that use
works well for me when working with modules and f2py
. (my code is basically fixed form Fortran 90). Assuming a main file main.f
, and a module subs.f90
(make sure there is module...end module
in subs.f90
, I would use the following sequence for compilation:
gfortran -ffixed-form -c subs.f90
f2py.py -c -m main -I/path/to/subs /path/to/subs/subs.f90main.f
Note that you might need to specify other options to f2py
depending on your system. For me, with MinGW on Windows, I need --compiler=mingw32
, since f2py
doesn't seem to be able to locate the C compiler otherwise.
Post a Comment for "F2py Giving "redefinition Of 'foo'... Previous Definition Was Here""