I am currently testing a Fortran module on two different compilers (ifort on a linux machine, gfortran on a mac), and I've run into a strange problem I cannot explain.
I have a simple module with one public subroutine and two functions it calls which are private. It looks something like 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 is the main program to test:
program sgtest
use test
implicit none
integer(kind=4) :: a,b
real(kind=8) :: output
a = 3
b = 4
call publicsub(a,b,output)
write *, output
end program sgtest
I can get the module to compile using ok by itself. When I compile the main program it will not compile under the ifort compiler on my linux box unless I also declare the function calls as integers in the main subroutine publicsub, I.E., I add this code to publicsub:
integer(kind=4) :: func1,func2
And then it works just fine. However, when I compile this on gfortran on my mac, I got these error messages:
Undefined symbols for 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 for architecture x86_64 collect2: error: ld returned 1 exit status
But then when I comment this declaration out, everything compiles and runs as expected with gfortran. Ironically, I get a similar error message from ifort on the linux box without these declarations.
So what's going on here? Is this a Fortran90/95 vs GNU Fortran extensions issue, or have I done something structurally that is a no-no with the module?