Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29277 Discussions

Strange link error - unresolved external symbol P.P322.TEST$FUNC.UP$

ferrad
New User
920 Views
I get the following link error:
error LNK2001: unresolved external symbol P.P322.TEST$FUNC.UP$
when I try to link the following code:
program main
implicit none
integer, parameter :: n = 2
external :: fred
call test(n, fred)
end
subroutine test(n, func)
implicit none
integer :: n
real*8, external :: func
return
contains
real*8 function func1(xp)
implicit none
real*8 :: xp(n)
integer :: k
func1 = func()
write(6,'(e16.8)') (xp(k),k=1,n)
return
end function
end subroutine
real*8 function fred()
fred = 100.0
return
end
Any idea what it means and how to fix it?
Adrian
0 Kudos
3 Replies
Lorri_M_Intel
Employee
920 Views

You didn't say, but I'm guessing you are building this with debug enabled, yes?

I wasn't able to reproduce it except with -Zi.

Obviously, it's a bug; please submit a support request. Unfortunately, it still fails with current sources.

- Lorri
0 Kudos
ferrad
New User
920 Views

Lorri,

Yes, debug enabled. I will submit to Premier Support.
Adrian

0 Kudos
jim_dempsey
Beginner
920 Views

The compiler should have generated an error message for your programming error. Instead the compiler has an error in that it "remembered" the external attribute of the dummy variable func in subroutine test when it nested into function func1. This resulted in code generated to call a local subroutine of the name func (appropriately name mangled).

The programming error (assuming you think your program is correct) is that func is a stack variable (dummy arg) to test. func1 can be called (it isn't in your sample code) without regard to subroutine nesting level, e.g. had your code contained func2, func3, func4.

Were test to call func1 it is concievable that the compiler could figure out where the dummy variable func is located (I do not think it does), but then consider what happens should func2 call func1. And func3 calling func2. Let alone a recursive call to any internal func let alone to test.

Now, this could be solved in the compiler if for subroutine test it creates a static name mangled variable (P.P322.TEST$FUNC.UP$), then copies the dummy argument func into this variable on entry and then substitutes all references to func to use the name mangled variable.

This would work as long as test was not recursively called with different function for func (this could be fixed with pushing/poping old value of P.P322.TEST$FUNC.UP$ on call/return of test).

This is either a compiler error or programming error, not a linker problem.

Jim Dempsey

0 Kudos
Reply