Calling subroutine in fortran module

A

Amit

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)
 
K

Keith Thompson

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)

Probably not here. The C language doesn't define the mechanism for
calling Fortran subroutines; it's likely to depend on the OS and on
the C and Fortran compilers. If the documentation for your Fortran
compiler doesn't have the information you need, you might try
comp.unix.programmer.
 
T

Tim Prince

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)
man nm
 
C

CBFalconer

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)

Not here. It's off topic and not remotely portable nor
standardized. Try a newsgroup that deals with your particular
system and compiler(s).
 
E

E. Robert Tisdale

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
.
.
.
> cat mpi_m.f90
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
> nm mpi_m.o
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.
 
D

Dave Thompson

Probably not here. The C language doesn't define the mechanism for
calling Fortran subroutines; it's likely to depend on the OS and on
the C and Fortran compilers. If the documentation for your Fortran
compiler doesn't have the information you need, you might try
comp.unix.programmer.

Or comp.lang.fortran, who do accept crosslanguage issues (as c.l.c
with its much higher traffic does not) and whose regulars have
experience with such issues on a variety of systems. But it is true
the correct answer frequently depends on your Fortan compiler (and
options) and sometimes your OS and/or C compiler, so specify them.

- David.Thompson1 at worldnet.att.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top