Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
22 Views

Unresolved external - why?

I have a simple module containing 2 subroutine and 1 function:

      module testbug

      contains

      SUBROUTINE sub1(n,x)
      IMPLICIT NONE
      INTEGER :: n
      REAL*8  :: x(n)
      REAL*8  :: f
      REAL*8  :: func3
      f = func3(n, x)
      return
      END SUBROUTINE sub1

      SUBROUTINE sub2(n,x)
      IMPLICIT NONE
      INTEGER :: n
      REAL*8  :: x(n)
      REAL*8  :: f
      REAL*8  :: func3
      f = func3(n, x)
      return
      END SUBROUTINE sub2

      REAL*8 FUNCTION func3(n,x)
      IMPLICIT NONE
      INTEGER :: n
      REAL*8  :: x(n)
      func3 = 0.5d0
      return
      END FUNCTION func3

      end module testbug

called by a test program:

      program main

      use testbug
      implicit none

      integer :: n = 2
      real*8  :: x(2)

      x(1) = -1.d0
      x(2) = +1.d0
      call sub1(n,x)

      end

Yet when I link with:  ifort main.f90 mod.f90, I get:

mod.obj : error LNK2019: unresolved external symbol _FUNC3 referenced in function _TESTBUG_mp_SUB1
main.exe : fatal error LNK1120: 1 unresolved externals

Any idea why?

0 Kudos
5 Replies
Highlighted
Valued Contributor II
22 Views

You declare the function func

You declare the function func as being external, remove the line "real*8 func" from the source code of sub1 and sub2.

Also you should invert the file names on the command-line: the compiler processes the files in the order in which they appear. It may be using an old module intermediate file to compile main.f90.

0 Kudos
Highlighted
Beginner
22 Views

Like this?

Like this?

      SUBROUTINE sub1(n,x)
      IMPLICIT NONE
      INTEGER :: n
      REAL*8  :: x(n)
      REAL*8  :: f
      external func3
      f = func3(n, x)
      return
      END SUBROUTINE sub1

?

Doesn't compile:

mod.f90(11): error #6404: This name does not have a type, and must have an explicit type.   [FUNC3]
      f = func3(n, x)
----------^

0 Kudos
Highlighted
Beginner
22 Views

Also why does it complain

Also why does it complain only about sub1, not sub2, which are identical?

mod.obj : error LNK2019: unresolved external symbol _FUNC3 referenced in function _TESTBUG_mp_SUB1
main.exe : fatal error LNK1120: 1 unresolved externals

0 Kudos
Valued Contributor II
22 Views

No, I meant completely remove

No, I meant completely remove it, not replace it ;). As for the reason the compiler/linker complains about only one, it may be that it is abbreviating the messages.

Just tested it to be sure and the compiler is completely satisfied with that solution.

0 Kudos
Highlighted
Beginner
22 Views

great thanks, works fine.

great thanks, works fine.

0 Kudos