First, note that your C function is SUBPRINT
not subprint
, that DOES matter even inside C.
Second, you should use __cplusplus
, not _cplusplus
Third, just use modern Fortran for interoperability with C:
c.cc:
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
void subprint(){
printf("hello the world\n");
}
#ifdef __cplusplus
}
#endif
f.f90:
program main
implicit none
interface
subroutine subprint() bind(C,name="subprint")
end subroutine
end interface
call subprint()
read(*,*)
endprogram
gfortran c.cc f.f90
./a.out
hello the world