- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to use abstract types with overloaded operations and I get unresolved
externals, whereas the compilation succceeds without any problem:
/tmp/ifortpV9nJv.o: In function `MAIN__':
sort_reduced.f90:(.text+0x914): undefined reference to `islower_'
sort_reduced.f90:(.text+0x990): undefined reference to `assignx_'
sort_reduced.f90:(.text+0xa40): undefined reference to `assignx_'
sort_reduced.f90:(.text+0xab4): undefined reference to `assignx_'
sort_reduced.f90:(.text+0xaf7): undefined reference to `print_'
/tmp/ifortpV9nJv.o: In function `sortable_types_mp_sort_':
sort_reduced.f90:(.text+0xd37): undefined reference to `islower_'
sort_reduced.f90:(.text+0xdad): undefined reference to `assignx_'
sort_reduced.f90:(.text+0xe5e): undefined reference to `assignx_'
sort_reduced.f90:(.text+0xecc): undefined reference to `assignx_'
The compiler is Intel Fortran 12.0.3 and the program is shown below.
It is longer than I had wanted, but the overloaded operations seem to
cause the problem.
Any suggestions as to how to repair this or is it a compiler error?
Regards,
Arjen
-----
! sort_reduced.f90 --
! Curious link errors
!
module sortable_types
type, abstract :: sortable
! No particular data
contains
procedure(islower), deferred :: islower
procedure(assignx), deferred :: assign_data
procedure(copy), deferred :: copy_data
generic :: operator(<) => islower
generic :: assignment(=) => assign_data
end type
abstract interface
logical function islower( item1, item2 )
import sortable
class(sortable), intent(in) :: item1, item2
end function islower
end interface
abstract interface
subroutine assignx( item1, item2 )
import sortable
class(sortable), intent(inout) :: item1
class(sortable), intent(in) :: item2
end subroutine assignx
end interface
! Workaround for Intel Fortran - "source =" not supported yet
abstract interface
subroutine copy( item1, item2 )
import sortable
class(sortable), intent(in) :: item1
class(sortable), intent(out), allocatable :: item2
end subroutine copy
end interface
contains
subroutine sort( array )
class(sortable), dimension(:), intent(inout), target :: array
class(sortable), allocatable :: tmp
class(sortable), pointer :: first_element
integer :: i
integer :: j
call array(1)%copy_data( tmp )
do i = 1,size(array)
do j = i+1,size(array)
if ( array(j) < array(i) ) then
tmp = array(i)
array(i) = array(j)
array(j) = tmp
endif
enddo
enddo
end subroutine sort
end module sortable_types
!
! Module and program to test the above
!
module addresses
use sortable_types
implicit none
type, extends(sortable) :: address_type
character(len=20) :: name
character(len=20) :: city
contains
procedure :: copy_data => copy_address
procedure :: assign_data => assign_address
procedure :: islower => islower_address
end type address_type
contains
subroutine assign_address( item1, item2 )
class(address_type), intent(inout) :: item1
class(sortable), intent(in) :: item2
select type (item2)
type is (address_type)
item1%name = item2%name
item1%city = item2%city
end select
end subroutine assign_address
subroutine copy_address( item1, item2 )
class(address_type), intent(in) :: item1
class(sortable), intent(out), allocatable :: item2
allocate( address_type :: item2 )
select type (item2)
type is (address_type)
item2%name = item1%name
item2%city = item1%city
end select
end subroutine copy_address
logical function islower_address( item1, item2 )
class(address_type), intent(in) :: item1
class(sortable), intent(in) :: item2
select type (item2)
type is (address_type)
if ( item1%name /= item2%name ) then
islower_address = item1%name < item2%name
else
islower_address = item1%city < item2%city
endif
end select
end function islower_address
end module addresses
program test_addresses
use addresses
implicit none
type(address_type), dimension(6) :: address
address = (/ address_type( "John", "London" ), &
address_type( "Jan", "Amsterdam" ), &
address_type( "Jan", "Warsaw" ), &
address_type( "Jean", "Paris" ), &
address_type( "Giovanni", "Rome" ), &
address_type( "Juan", "Madrid" ) /)
call sort( address )
call print( address )
end program test_addresses
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I will let the developers know about this. Issue ID is DPD200173134.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page