主题:在fortran的动态链接库中怎么引用外部的过程
现有如下代码:
**** modll.f90 ****
module global
implicit real(kind(1.d0)) (a-h,o-z)
!DEC$ ATTRIBUTES DLLEXPORT :: x, n
allocatable :: x(:)
integer :: n
contains
subroutine tsum(ave)
!DEC$ ATTRIBUTES DLLEXPORT :: tsum
real*8 :: ave
call initial
write(*,"('dll: the array is: ',/,i4,/,10(5x,5f10.4))") n,(x(i),i=1,n)
ave = 0
do i = 1, n
ave = ave + x(i)
enddo
ave = ave / real(n)
return
end subroutine tsum
end module global
----------------------------------------------------------
**** test.f90 ****
program test
use global
!
real*8 ave
call tsum(ave)
write(*,"('the average is: ',/,5x,f10.4)") ave
end
!
subroutine initial()
use global
n = 5
allocate(x(n))
do i = 1, n
x(i) = 10.d0*sin(3.14/real(i))
enddo
end subroutine initial
-----------------------------------------------------------
我如何让modll.f90可以编译成dll,并让编译器知道要调用的initial子程序在其它源代码中,并在运行时再链接这个子程序?
**** modll.f90 ****
module global
implicit real(kind(1.d0)) (a-h,o-z)
!DEC$ ATTRIBUTES DLLEXPORT :: x, n
allocatable :: x(:)
integer :: n
contains
subroutine tsum(ave)
!DEC$ ATTRIBUTES DLLEXPORT :: tsum
real*8 :: ave
call initial
write(*,"('dll: the array is: ',/,i4,/,10(5x,5f10.4))") n,(x(i),i=1,n)
ave = 0
do i = 1, n
ave = ave + x(i)
enddo
ave = ave / real(n)
return
end subroutine tsum
end module global
----------------------------------------------------------
**** test.f90 ****
program test
use global
!
real*8 ave
call tsum(ave)
write(*,"('the average is: ',/,5x,f10.4)") ave
end
!
subroutine initial()
use global
n = 5
allocate(x(n))
do i = 1, n
x(i) = 10.d0*sin(3.14/real(i))
enddo
end subroutine initial
-----------------------------------------------------------
我如何让modll.f90可以编译成dll,并让编译器知道要调用的initial子程序在其它源代码中,并在运行时再链接这个子程序?