This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Bug 78737 - linking error with deferred, undefined user-defined derived-type I/O
- From: Damian Rouson <damian at sourceryinstitute dot org>
- To: gfortran <fortran at gcc dot gnu dot org>
- Cc: Jerry DeLisle <jvdelisle at gcc dot gnu dot org>, Paul Richard Thomas <paul dot richard dot thomas at gmail dot com>
- Date: Thu, 8 Dec 2016 07:54:23 -0800
- Subject: Bug 78737 - linking error with deferred, undefined user-defined derived-type I/O
- Authentication-results: sourceware.org; auth=none
A linking error results when an abstract type defers a user-defined derived type output binding that is not implemented anywhere in the program:
$ cat undefined-ud-dtio.f90
module object_interface
type, abstract :: object
contains
procedure(write_formatted_interface), deferred ::write_formatted
generic :: write(formatted)=>write_formatted
end type
abstract interface
subroutine write_formatted_interface(this,unit,iotype,vlist,iostat,iomsg)
import object
class(object), intent(in) :: this
integer, intent(in) :: unit
character (len=*), intent(in) :: iotype
integer, intent(in) :: vlist(:)
integer, intent(out) :: iostat
character (len=*), intent(inout) :: iomsg
end subroutine
end interface
contains
subroutine assert(a)
class(object):: a
write(*,*) a
end subroutine
end module
end
$ gfortran undefined-ud-dtio.f90
Undefined symbols for architecture x86_64:
"_write_formatted_interface_", referenced from:
___object_interface_MOD_assert in ccMQHXbf.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
$ gfortran --version
GNU Fortran (MacPorts gcc7 7-20161127_0) 7.0.0 20161127 (experimental)
Adding a type that defines the binding eliminates the linking error.
Damian
________________________________
Damian Rouson, Ph.D., P.E.
President, Sourcery Institute
http://www.sourceryinstitute.org
+1-510-600-2992 (mobile)