This is a follow up to my previous question. I wrapped my Fortran code in a module and now it compiles when I run:
R CMD SHLIB ./Fortran/Fpi.f90
Your problem comes down to the declaration of dboard
:
double precision :: pi_est, homepi, pirecv, pisum, dboard
Here you are saying that dboard
is an external function, rather than a module procedure. This explains why there is a symbol dboard_
coming into play. You want to remove that:
double precision :: pi_est, homepi, pirecv, pisum
and instead rely, in pi
on the module procedure-ness of dboard
: pi
already knows about it without this declaration.
Now, beyond that, because pi
is in a module there is going to be some name mangling going on for that subroutine itself. I'd solve this problem by making pi
itself a (C) interoperable procedure.
Module Fpi
IMPLICIT NONE
contains
subroutine pi(avepi, DARTS, ROUNDS) bind(C)
use, intrinsic :: iso_c_binding, only : c_double, c_int
real(c_double), intent(out) :: avepi
integer(c_int), intent(in) :: DARTS, ROUNDS
...
and then using .C
rather than .Fortran
.
You can keep pi
and dboard
in the module, and this latter needn't even be interoperable.