Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29284 Discussions

Unresolved externals with abstract types and overloaded operations

Arjen_Markus
Honored Contributor II
1,237 Views
Hello,

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

0 Kudos
7 Replies
Steven_L_Intel1
Employee
1,237 Views
Hmm. We had fixed a problem almost exactly like this, but this example still fails. Argh. (You did not supply routine PRINT but that's not part of the problem. Can you add that just so we can have a complete program?)

I will let the developers know about this. Issue ID is DPD200173134.
0 Kudos
Arjen_Markus
Honored Contributor II
1,237 Views
I will send you the complete program tomorrow, but you can also remove the call to print in the main program.
That ought to make it a complete program, even if it produces no output.
0 Kudos
Steven_L_Intel1
Employee
1,237 Views
Yes, I already did that, but it would be nice to have the output just to verify that the program is executing correctly.
0 Kudos
Arjen_Markus
Honored Contributor II
1,237 Views
I have added the complete source file as an attachment.
The expected output is (give or take a few spaces):

Giovanni Rome

Jan Amsterdam

Jan Warsaw

Jean Paris

John London

Juan Madrid

Regards,

Arjen

0 Kudos
velvia
Beginner
1,237 Views
Hi. I have exactly the same problem here with the following code. Best regards, Francois
0 Kudos
Steven_L_Intel1
Employee
1,237 Views
Thanks, I'll add that to make sure it gets fixed.
0 Kudos
Steven_L_Intel1
Employee
1,237 Views
The fix for this proved to be more complicated than one might expect. The fix has been made for a release later this year.
0 Kudos
Reply