Using deferred bindings
Ralph Kube
ralphkube@googlemail.com
Mon Nov 1 10:08:00 GMT 2010
Hello,
I am trying to compile fortran code that uses deferred bindings. The
full code is listed in section A1 from this paper:
http://portal.acm.org/citation.cfm?id=1644001.1644004.
It consists of 3 files, integrable_model.f03, lorenz.f03 and main.f03,
all 3 adhere to the fortran 2003 standard.
In integrable_model, An abstract type, integrable_model is defined
which contains the deferred procedures and defines new operators
module integrable_model_module
type, abstract, public :: integrable_model
contains
procedure(time_derivative), deferred :: d_dt
procedure(symmetric_operator), deferred :: add
procedure(symmetric_assignment), deferred :: assign
procedure(asymmetric_operator), deferred :: multiply
generic, public :: operator(+) => add
generic, public :: operator(*) => multiply
generic, public :: operator(=) => assign
end type integrable_model
...
end module integrable_model_module
in the file integrable_model.f03
An integrable model is implemented in the file lorenz.f03
and extended with the lorenz type:
module lorenz_module
type, extends(integrable_model), public :: lorenz
contains
procedure, public :: d_dt => dLorenz_dt
procedure, public :: add => add_lorenz
procedure, public :: multiply => multiply_lorenz
procudure, public :: assign => assign_lorenz
...
end type lorenz
...
end model lorenz_module
The code snippets above shows only the declaration of the deferred
type-bound procedure bindings and omits the abstract interface
declaration which is included in the file integrable_model.f03
Compiling and linking these files yields the following errors:
gfortran -fdefault-real-8 -std=f2003 -fno-underscoring -Wall -c
integrable_model.f03
gfortran -fdefault-real-8 -std=f2003 -fno-underscoring -Wall -c lorenz.f03
gfortran -fdefault-real-8 -std=f2003 -fno-underscoring -Wall
-L/Users/ralph/source/design_patterns/lorenz
-I/Users/ralph/source/design_patterns/lorenz -o main integrable_model.o
lorenz.o main.f03
Undefined symbols:
"_symmetric_operator", referenced from:
___integrable_model_module_MOD_integrate in integrable_model.o
"_symmetric_assignment", referenced from:
_d_dt.1554 in integrable_model.o
___integrable_model_module_MOD_integrate in integrable_model.o
"_asymmetric_operator", referenced from:
___integrable_model_module_MOD_integrate in integrable_model.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [main] Error 1
To me, it seems as if the module integrable_model would expect an
implementation of the deferred type-bound procedures in the file
integrable_model.f03. But the whole key of this program is that their
actual implementation is deferred to the place, where the extended type
implements them.
Do I see it correctly, that the linker is unaware that the actual
implementation of symmetric_operator, symmetric_assignment and
asymmetric_operator are not to be found in integrable_model.o ?
Cheers, Ralph
More information about the Fortran
mailing list