The code below is part of file recipes.f90 which is the source code for my user library librecipes.lib. It originally linked with my main program and worked correctly.
Then I decided to change it to a module by adding to recipes.f90 the text:
module recipes
Contains
....The same code as before....
end module recipes
Now when I produce the recipes.mod and librecipes.lib files there are no errors, nor in compiling the main program source code files into .obj files. But when linking, I get the following message:
librecipes.lib(recipes.obj): error LNK2001: unresolved external symbol _COS_VEC@8
Cos_Vec is only called by Cosfl_Sla and is not used elsewhere. As a work-around, I commented Cosfl_Sla out of recipes.f90 and successfully used Cos_Vec in the main program with appropriate arguments. But I am baffled by this one. Would someone please point out my stupid mistake.
!
function Cosfl_Sla(xa,x,u)
!
! Function Cosfl_Sla calculates the cosine of the angle between
! the flight line of the projectile and its sight line from the
! tracking radar antenna.
!
! Arguments:
! xa(3) Co-ordinates of radar antenna.
! x(3) Co-ordinates of projectile.
! u(3) Velocity vectors of projectile.
!
implicit none
real*8, intent(in) :: xa(3), x(3), u(3)
real*8 x1(3), Cosfl_Sla, Cos_Vec
x1 = x-xa
Cosfl_Sla = Cos_Vec(x1,u)
end function Cosfl_Sla
!
function Cos_Vec(a,b)
!
! Function Cos_Vec calculates the cosine of the angle between
! vectors a & b.
! Arguments : a(3) First vector.
! b(3) Second vector.
!
implicit none
real*8, intent(in) :: a(3), b(3)
real*8 a2, b2, ab, Cos_Vec
a2 = Dot_Product(a,a)
b2 = Dot_Product(b,b)
ab = Dot_Product(a,b)
if (a2 == 0.D0 .OR. b2 == 0.D0) then
Cos_Vec = 1.D0
else
Cos_Vec = ab/DSQRT(a2*b2)
end if
end function Cos_Vec
Alan
LNK2001 Error
For more complete information about compiler optimizations, see our Optimization Notice.

