From: Aris on
I admit that I should just learn how to use the EXTERNAL statement
correctly, but the gfortran compiler doesn't help me very much.
Consider the small program


module my_module
!
contains
!
subroutine sub
external func ! This statement is apparently wrong
call ext_sub( func )
end subroutine
!
function func( x ) result(value)
value = 2*x
end function
!
end module
!
!
program test
use my_module
call sub
end program
!
!
subroutine ext_sub( f )
external f
print*, f(1.)
end subroutine


GNU Fortran (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu4)

swallows the program, while

GNU Fortran (Ubuntu 4.3.3-5ubuntu4) 4.3.3

says

/tmp/ccWLYnfa.o: In function `__my_module_MOD_sub':
test.f90:(.text+0x24): undefined reference to `func_'
collect2: ld returned 1 exit status
From: m_b_metcalf on
On Feb 18, 10:31 am, Aris <u...(a)domain.invalid> wrote:
> I admit that I should just learn how to use the EXTERNAL statement
> correctly, but the gfortran compiler doesn't help me very much.
> Consider the small program
>
> module my_module
> !
> contains
> !
> subroutine sub
> external func ! This statement is apparently wrong
> call ext_sub( func )
> end subroutine
> !
> function func( x ) result(value)
> value = 2*x
> end function
> !
> end module
> !
> !
> program test
> use my_module
> call sub
> end program
> !
> !
> subroutine ext_sub( f )
> external f
> print*, f(1.)
> end subroutine
>
> GNU Fortran (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu4)
>
> swallows the program, while
>
> GNU Fortran (Ubuntu 4.3.3-5ubuntu4) 4.3.3
>
> says
>
> /tmp/ccWLYnfa.o: In function `__my_module_MOD_sub':
> test.f90:(.text+0x24): undefined reference to `func_'
> collect2: ld returned 1 exit status

The error message is correct. The function func is in the same module
as sub and so the interface is explicit. Adding an external statement
implies that a different, *external*, function func exists, which it
doesn't.

Regards,

Mike Metcalf