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

How to call a dll (built by fortran) in Fortran?

lyricx
Beginner
646 Views
I tried the following example, but didn't succeed.
I am not familar with how to call a dll. what is the problem with my calling?
some one can give some help? thanks!

!----- the main program calling a dll

PROGRAM DLLTEST
IMPLICIT NONE
INTERFACE
SUBROUTINE ARRAYTEST (sarray)
!DEC$ ATTRIBUTES DLLIMPORT:: ARRAYTEST
REAL(4) sarray(3, 7)
END SUBROUTINE ARRAYTEST
END INTERFACE
REAL(4) sarray(3,7)
CALL ARRAYTEST(sarray)
WRITE(12,*) sarray(:,:)
END PROGRAM DLLTEST


! --------- the program used for generating a dll
! ARRAYtest.f90
!
! FUNCTIONS/SUBROUTINES exported from ARRAYtest.dll:
! ARRAYtest - subroutine
!
SUBROUTINE ARRAYTEST(arr)
!DEC$ ATTRIBUTES DLLEXPORT :: ARRAYTEST
REAL(4) arr(3, 7)
INTEGER i, j
DO i = 1, 3
DO j = 1, 7
arr (i, j) = 11.0 * i + j
END DO
END DO
END SUBROUTINE
0 Kudos
4 Replies
lyricx
Beginner
646 Views
when I compile the main program, the error is:
---
dlltest error LNK2019: unresolved external symbol __imp__ARRAYTEST referenced in function _MAIN__
dlltest fatal error LNK1120: 1 unresolved externals

---

it seems that the main program can't recognize the dll.
something wrong with my implementation?
0 Kudos
anthonyrichards
New Contributor III
646 Views
Did you include the DLL's export library ARRAYTEST.LIB in your project when building your test program?
0 Kudos
lyricx
Beginner
646 Views
solved,
it is successful when deleting " !DEC$ ATTRIBUTES DLLIMPORT:: ARRAYTEST".
0 Kudos
Steven_L_Intel1
Employee
646 Views
Then you are not linking to the DLL export library and probably not using the DLL.
0 Kudos
Reply