Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

interface block with module names

niessner
Beginner
552 Views
How do I define an interface block for subroutines/functions that exist in another module when all I have is the library from those modules?
Suppose I have a module that has some subroutine/function that I want to share like this:
module foo
contains
subroutine bar
end subroutine bar
end module foo
I then write a test main program to make sure it is correct:
program test
use foo
implicit none
call bar
end program test
All compiles and runs. Now that my library is built (foo.a from foo.o) I want to give it to all my friends. However, how do they implement the interface?
If I do:
program main
implicit none
interface
subroutine bar
end subroutine bar
end interface
call bar
end program main
and then compile I get a missing symbol bar_. I figure this is correct because the original symbol was generated with bar being in module foo so there is some name mangelation that makes it look more like foo_mp_bar_. Do I just make the interface foo_mp_bar or is there some special syntax that will do the name mangelation for me? I know that ifort will work but some compilers like (achem) gfortran prepend underscores which cannot be leading characters in subroutine names. I guess I am looking for a compiler indepenedent way to specify the interface.
Thanks for any and all help in advance.
0 Kudos
1 Reply
Steven_L_Intel1
Employee
552 Views
You have to give them the .mod as well - this handles the name mangling. You don't want them to have to repeat the declaration. This does require them to have Intel Fortran, though.

One option for you is to add BIND(C) to each of your module procedures. For example:

...
subroutine bar () bind(C)
...

And you could then provide a .f90 source to a module that looks like this:

module foo
interface
subroutine bar () bind(C)
end subroutine bar
end interface
end module foo

They could compile this with their favorite compiler (that supports BIND(C)) and the names would come out right.

Do be aware that mixing objects from different Fortran compilers may not work.
0 Kudos
Reply