- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
----------^
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
great thanks, works fine.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page