我正试图绕过fortran 90,我有这个玩具示例,我想问一个问题
module foo
implicit none
contains
subroutine foobar()
print *,'foobar'
end subroutine foobar
end module foo
然后是主程序 -
program test
use foo
real a,b,c
a = 10.
b= 10.
c= 10.
print *,'hello world'
call abc(a,b,c)
end program test
subroutine abc(a,b,c)
call def(a,b,c)
end subroutine abc
subroutine def(a,b,c)
call foobar()
print *,'def'
end subroutine def
如果我在子例程def中没有包含'use foo'语句,那么在链接test.o和foo.o-undefined reference时会出现链接错误。这是为什么 ?通过在'main'级别声明使用foo,子例程是否也无法访问符号foo? 我猜不会基于编译器错误。所以这意味着前进的唯一方法是在每个子例程中包含use foo语句。这背后的动机是什么?