Reputation: 155
I have set of blas/lapack functions that I got from NETLIB website. I would like to put these functions inside a Fortran module. The rest of my code is in Fortran 90. So I go about doing this:
module modname
contains
double precision function ddot(n,dx,incx,dy,incy)
.
.
.
end function
subroutine dpofa(a,lda,n,info)
.
.
double precision ddot
.
end subroutine dopfa
end module
When I compile using
gfortran modname.f90
I get the following error:
/tmp/ccC2EUFj.o: In function
__temp_MOD_dpofa': temp.f90:(.text+0x11c): undefined reference to
ddot_'
I am ignoring the error about Undefined reference to main
, I realize it happens because I do not have program .. end program statements in the file.
If, however, I remove the lines with module modname
, contains
and end module
the compiler compiles without any issues.
What could possibly be the issue?
Upvotes: 2
Views: 888
Reputation: 32366
In your non-module approach you have lots of external functions and subroutines. That is, if these are defined outside the module then one procedure has no clue about another. You tell the subroutine dpofa
about the function ddot
by using the declaration statement double precision ddot
. The compiler mangles that name to ddot_
(see elsewhere for details of that) and also mangles the name of the real function you have to the same. The linker resolves one symbol to the other when needed.
When you come to using a module, you still have this external function declaration, but now the real function you have, in the same module, is no longer external. Instead, there is a module procedure which gets mangled to something like __temp_MOD_ddot
. You aren't creating a function with the mangled name ddot_
any longer.
You presumably have a reference to the function ddot
in dpofa
, but in the module version that will be to the symbol ddot_
which isn't defined.
You'll want to remove the function declarations for those functions which are now defined in the same module, and are no longer external.
Upvotes: 3