Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Honored Contributor I
42 Views

Unexpected linker error "LNK2001: unresolved external symbol" and an ICE

The following simple code compiled using Intel Fortran compiler 17 update 1 and no optimization (/Od option) generates a linker error I have never seen before, "unresolved external symbol ????":  With optimization (/O), compilation of the main program results in an internal compiler error.

module m

   implicit none

   private

   type :: t
      private
      procedure(Ifoo), nopass, pointer :: m_foo_ptr => foo
   contains
      private
      procedure, nopass :: foo
      procedure, pass(this), public :: bar
   end type t

   abstract interface

      pure subroutine Ifoo( this )

         import :: t

         implicit none
         
         !.. Argument list
         type(t), intent(inout), optional :: this

      end subroutine Ifoo

   end interface

   interface t
      module procedure construct_t
   end interface t
   
   public :: t

contains

   function construct_t( foo_ptr ) result( new_t )

      !.. Argument list
      procedure(Ifoo), optional :: foo_ptr
      !.. Function result
      type(t) :: new_t

      if ( present( foo_ptr ) ) then
         new_t%m_foo_ptr => foo_ptr
      end if

      return

   end function construct_t

   pure subroutine foo( this )

      !.. Argument list
      type(t), intent(inout), optional :: this
      
      if ( present(this) ) then
      end if
      
      return

   end subroutine foo

   subroutine bar( this )

      !.. Argument list
      class(t), intent(inout) :: this

      if ( associated(this%m_foo_ptr) ) then
         call this%m_foo_ptr( this )
      end if

      return

   end subroutine bar

end module m
program p

   use m, only : t

   implicit none

   type(t) :: foo

   call foo%bar()
   
   stop

end program p

Here's the information on the linker error:

C:\..>ifort /c /Od /standard-semantics /stand /warn:all m.f90
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R
) 64, Version 17.0.1.143 Build 20161005
Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.


C:\..>ifort /c /Od /standard-semantics /stand /warn:all p.f90
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R
) 64, Version 17.0.1.143 Build 20161005
Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.


C:\..>link /out:p.exe /subsystem:console p.obj m.obj
Microsoft (R) Incremental Linker Version 14.00.24215.1
Copyright (C) Microsoft Corporation.  All rights reserved.

p.obj : error LNK2001: unresolved external symbol ????
p.exe : fatal error LNK1120: 1 unresolved externals

Here're the details of the internal compiler error, shown with /O1 optimization but the error occurs with all three levels:

C:\..>ifort /c /O1 /standard-semantics /stand /warn:all m.f90
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R
) 64, Version 17.0.1.143 Build 20161005
Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.


C:\..>ifort /c /O1 /standard-semantics /stand /warn:all p.f90
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R
) 64, Version 17.0.1.143 Build 20161005
Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.

fortcom: Fatal: There has been an internal compiler error (C0000005).
compilation aborted for p.f90 (code 1)

 

0 Kudos
1 Reply
Highlighted
Employee
42 Views

I have never seen that one either. Thank you for reporting this and for the reproducer. I reproduced both issues and escalated them to Development.

(Internal tracking id: DPD200416660 - internal compiler error)
(Internal tracking id: DPD200416661 - link error unresolved external symbol ????)

0 Kudos