I need to wrap a simply fortran90 code with f2py. The fortran module "test.f90" is
module util
contains
FUNCTION gasdev(idum)
implicit none
INTEGER(kind=4), intent(inout) :: idum
REAL(kind=8) :: gasdev, ran2
print*,idum
gasdev = ran2(idum)
return
END FUNCTION
FUNCTION ran2(idum)
implicit none
INTEGER(kind=4), intent(inout) :: idum
REAL(kind=8) :: ran2
print*,idum
ran2=2.D0
return
END FUNCTION
end module util
and then I wrap it with
f2py -m test -c test.f90
but when I import it in python
In [2]: import test
it prompted me with error saying
ImportError: ./test.so: undefined symbol: ran2_
Any ideas on how to fix it? Thanks.
In function gasdev you declare ran2 as an external function. As you then don't link in any such function importing the module will fail.
Instead, remove the declaration of ran2 in gasdev, in which case the ran2 call uses the explicit interface to the ran2 function in the module, and everything works.