Amit said:
I tried calling a subroutine in a Fortran module from C but couldn't.
I always get the error: undefined reference in the main.o file
(main is in C calling the subroutine).
for calling the subroutine I used the following name:
modulename_MP_subroutinename_(...)
and all possible variant (upper case,lower case).
Can anybody help (for a unix system)
NM(1) GNU Development Tools NM(1)
NAME
nm - list symbols from object files
.
.
.
MODULE mpi_m
double precision, save :: t_tic, t_toc
CONTAINS
subroutine mpi_tic()
implicit none
t_tic = MPI_WTIME()
end subroutine mpi_tic
subroutine mpi_toc(dt)
implicit none
double precision, INTENT(OUT) :: dt
t_toc = MPI_WTIME()
dt = (t_toc - t_tic)
end subroutine mpi_toc
END MODULE mpi_m
00000024 C _CMPIPRIV
00000050 C _D_in_MPI_M
00000000 T __MPI_TIC_in_MPI_M
00000040 T __MPI_TOC_in_MPI_M
U MPI_WTIME
Notice that the symbols created
for subroutines contained in modules
are mangled differently from external functions.
In this case, my Absoft Fortran 90 compiler
folds the subroutine name to upper case,
prepends double underscore
and appends in_MPI_M (the module name folded to uppercase.)
Some Fortran compilers create symbols
that cannot be expressed as C identifiers.
To make your code portable,
you will need to write an external "wrapper" subroutine
that uses the module and then call the wrapper
instead of the module function.