LNK2001 Error

LNK2001 Error

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

2 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项

My apologies for the double posting - a bit of finger trouble.

I have found my stupid mistake, an almost infallible result of posting such things on the forum.

I should have removed the declaration of Cos_Vec from Cosfl_Sla when converting the file to a module.

Alan

登陆并发表评论。