fortran - Declare functions as variables in Fortran90 modules? ifort says yea, gfortran says nay -


i testing fortran module on 2 different compilers (ifort on linux machine, gfortran on mac), , i've run strange problem cannot explain.

i have simple module 1 public subroutine , 2 functions calls private. looks this:

module test implicit none private public :: publicsub  contains  subroutine publicsub(x,y,arg) implicit none integer(kind=4), intent(in):: x,y real(kind=8),   intent(out):: arg  arg = func1(x)*10. / func2(y)  end subroutine publicsub  integer(kind=4) function func1(x) implicit none integer(kind=4), intent(in):: x  func1 = x*x;  end function func1  integer(kind=4) function func2(x) implicit none integer(kind=4),intent(in):: x  func2 = x*x*x  end function func2 end module test 

here main program test:

program sgtest  use test  implicit none   integer(kind=4) :: a,b real(kind=8) :: output  = 3 b = 4  call publicsub(a,b,output)  write *, output  end program sgtest  

i can module compile using ok itself. when compile main program not compile under ifort compiler on linux box unless declare function calls integers in main subroutine publicsub, i.e., add code publicsub:

integer(kind=4) :: func1,func2 

and works fine. however, when compile on gfortran on mac, got these error messages:

undefined symbols architecture x86_64:

 "_func1_", referenced from:      ___test_mod_publicsub in ccnj2zt6.o  "_func2_", referenced from:      ___test_mod_publicsub in ccnj2zt6.o 

ld: symbol(s) not found architecture x86_64 collect2: error: ld returned 1 exit status

but when comment declaration out, compiles , runs expected gfortran. ironically, similar error message ifort on linux box without these declarations.

so what's going on here? fortran90/95 vs gnu fortran extensions issue, or have done structurally no-no module?

we cannot ay wrong in original code, because not show main program. answer question title:

when this:

subroutine publicsub(x,y,arg)   integer(kind=...), intent(in):: x,y   real(kind=...),   intent(out):: arg   !!   integer(kind=...) :: func1,func2   !!    arg = func1(x) * 10 / func2(y)  end subroutine publicsub 

you declaring, func1 , func2 external function distinct func1 , func2 in module.

and because have no such external functions outside of module, linker cannot find them , linking ends error.

the added line should not there.


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -