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

Exporting & Importing Fortran DLL to a Fortran Application

Burak_C_
Beginner
1,713 Views

Hi,

I try to implement a simple example (link) to import Fortran dll within Visual Fortran IDE. I compile and build the dll correctly , I guess. Also, in the main program , I introduce corresponding

.lib file's directory 

(Properties -> Configuration Properties -> Linker -> General -> Additional Library Directories and type the path like "D:\ForDllTest\Debug) 

and the lib file itself

(Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies and type the path like ForDLL.lib)

Also, I copy the corresponding DLL to the main project directory. When I compile the main program, it gives the following error.

Error    1     error LNK2019: unresolved external symbol __imp__ARRAYTEST referenced in function _MAIN__    FortTest.obj

I follow the official notes (Building Executables that Use DLLs). But, it doesn't work. Is there any mistake on setting the lib's location?

Would someone explain the reasons via Visual Fortran IDE (not from command window pls) ? I have checked lots of documents but until now none explain it clearly. Everybody mentions in a more complex way.

Thanks in advance...

 

DLL's Code:

!  FortDLL.f90 
!
subroutine FortDLL(arr)

  ! Expose subroutine FortDLL to users of this DLL
  !
  !DEC$ ATTRIBUTES DLLEXPORT::FortDLL
    REAL(4) arr(3, 7)
    INTEGER i, j
    PRINT *, "Fortran DLL is called ... "
    DO i = 1, 3
        DO j = 1, 7
            arr (i, j) = 11.0 * i + j
            PRINT *, "arr(i,j) = ", arr(i,j)
        END DO
    END DO
  ! Variables
   PRINT *, "END of Fortran DLL ..."
 ! Body of FortDLL

end subroutine FortDLL

Main Program Code:

!  FortTest.f90 


    program FortTest

    implicit none
    !DEC$ ATTRIBUTES DLLIMPORT:: ARRAYTEST
    REAL(4) rarray (3,7)
    CALL ARRAYTEST(rarray)
    ! Variables

    ! Body of FortTest
    print *, 'Hello World'

    end program FortTest

 

 

 

 

0 Kudos
2 Replies
mecej4
Honored Contributor III
1,713 Views

Change the name of the exported subroutine to ARRAYTEST, to match what your DLL consumer program expects.

0 Kudos
Burak_C_
Beginner
1,713 Views

Thank you very much,

What a big mistake I've done!

0 Kudos
Reply