I'm trying to learn how to call a Fortran function or subroutine from a C program and I made this simple example:
The Fortran function area.f90 is
function Area_Circle(r)
implicit none
real(kind(1.d0)) , intent(out):: Area_Circle
real(kind(1.d0)), intent(in) :: r
real(kind(1.d0)), parameter :: Pi = acos(-1.d0)
Area_Circle = Pi * r * r
end function Area_Circle
and the C main.c program
#include <stdio.h>
extern double Area_Circle_(double *r);
int main(int argc, char **argv){
double r;
printf("Enter the radius\n");
scanf("%lf", &r);
printf("The area is %lf\n", Area_Circle_(&r));
return 0;
}
I tried to compile and build with the command
gcc -o app main.c area.f90 -lgfortran
and the exit is
area.f90:1:0:
function Area_Circle(r)
Error: Symbol at (1) is not a DUMMY variable
What should I do to compile and run correctly this?
P.D.: I don't usually work in Fortran but some of my colleagues yes. For this reason I want to learn Fortran-C interoperativity.