I have a main program TEST and two modules A and B, shown below.
TEST uses B, and B uses A. TEST and B are in the same directory, say P,
but A is in a different directory, say Q. Entities from A are accessed
in B with ONLY. The default accessibility for B is PRIVATE, and none of
the entities from A that are accessed in B are explicitly declared by B
to be public. B has an integer variable Y that has an initial value
provided by a parameter X accessed from A, but Y is not accessed in TEST.
The problem described below is not sensitive to whether Y is private or
public, or (if Y is public) whether it is accessed in TEST. The problem
goes away if Y is deleted, or doesn't have an initial value given by the
parameter X from A.
I get the same problem if TEST isn't a main program.
If I compile like this (where xyz is a compiler name)
cd Q
xyz -c a.f90
cd P
xyz -c -I Q b.f90
xyz -c test.f90
I get error messages, sometimes entirely inscrutable, and sometimes
indicating that the compiler can't find A while it's compiling TEST.
Given that TEST doesn't access A directly, and doesn't access Y from B,
this seems a bit bizarre.
If I change the last command to
xyz -c -I Q test.f90
it works.
Which compilers have this search requirement?
I've attached a little GNU-zip-compressed tar file that illustrates the
problem. It contains ./a.f90, ./script, ./lower/b.f90 and ./lower/test.f90.
Running "./script" explains the (simple) usage:
"./script compiler last-compile-options..."
I ran it with "./script lf95" and it illustrated the problem. I ran
it with "./script lf95 -I.." and it works (lf95 is Lahey/Fujitsu Fortran
95 for Linux version 5.5). I get the same results with lf95 replaced
by f95, where f95 is NAG Fortran 95 for Linux, version 4.0, either build
310 or build 389.
Here are the files as text, so that you can look at them without expanding
the tar file. Remember that B and TEST are in a different directory
from the one containing A.
===========================================================================
module A
integer, public, parameter :: X = 1
end module A
module B
use A, only: X
private
integer, public :: Y = X
integer, public :: Z = 0
end module B
program TEST
use B, only: Z
print *, Z
end program TEST
===========================================================================
Best regards,
Van Snyder
|