Hi, FJ:
As of yesterday, I came into the need of the exact same thing; I followed your suggestion and things seem to compile and run just fine for as long as I never attempt to manipulate the arrays...but as soon as I add code for array, things do not even compile.
Here is the Fortran subroutine:
!============================================
subroutine fnet(n,a,b) bind(c,name="fnet")
use iso_c_binding
integer (c_int) :: n
real (c_double) :: b
real (c_double) :: a
integer i
b = n*2.0
! do i = 1,n
! a(i) = 1.0*i
! end do
return
end
!============================================
Here is the calling C program:
!============================================
#include <stdio.h>
void foo(int *n, double *a, double *b);
int main(int argc, char *argv[] )
{
int n;
double a[9];
double b;
n=10 ;
fnet(&n,a,&b);
fprintf(stderr, "b = %f\n", b);
return(0) ;
}
!============================================
And here are the error messages when attempting to compile the programs after uncommenting the commented lines in the Fortran subroutine.
g95 -i4 -r8 -fzero -fstatic -fbounds-check -fno-underscoring -fsloppy-char -O2 -ftrace=none -c fnet.f90 -o lnx/fnet.o
gcc -msse -msse2 -mfpmath=sse -O2 -c testc.c -o lnx/testc.o
gcc -static -s -o lnx/testc.exe lnx/fnet.o lnx/testc.o -lm
lnx/fnet.o(.text+0xaf): In function `fnet':
: undefined reference to `_g95_filename'
lnx/fnet.o(.text+0xb9): In function `fnet':
: undefined reference to `_g95_line'
lnx/fnet.o(.text+0xc2): In function `fnet':
: undefined reference to `_g95_array_oob2'
collect2: ld returned 1 exit status
make: *** [lnx/testc.exe] Error 1
Any ideas what this is due to?
Thanks
gsal