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

Error importing array variable from FORTRAN module

aurora
Beginner
950 Views

Hi,

I'm trying to import some module data that is stored (and exported) from a dll. Also, I have a module.dll that exports a variable (cubature2Dt_lengths) and then in my main code I want to use this variable.

module.dll:
-----------------------------

MODULE cubature2Dt
!DEC$ ATTRIBUTES DLLEXPORT ::cubature2Dt_lengths

IMPLICIT NONE

INTEGER, DIMENSION(10), PARAMETER :: cubature2Dt_lengths=(/1,3,4,6,7,9,13,16,19,25/)

END MODULE cubature2Dt

------------------------------

 

code in exec that imports module.dll:
-------------------------------
SUBROUTINE subr(a1)

!DEC$ ATTRIBUTES DLLIMPORT ::cubature2Dt_lengths

USE cubature2Dt,
-------------------------------

but this results in a compiler option (two times defined cubature2Dt_lengths- with dllimport, and with USE statement). And then, if I remove the "DLLIMPORT" line, a unresolved symbol linker error appears. This linker problem does not happen with subroutines or single variables (doubles, integers) defined in the submodule. Is there any issue with arrays inside modules like the one in my example? Is it possible what I'm trying? How should this be done?

 

 

 

Thanks in advance

0 Kudos
1 Solution
mecej4
Honored Contributor III
950 Views

Please build and run the DLL_Shared_Data example in the compiler installation folders. If you do not configure and build the code correctly, what will happen is that both the DLL and the EXE contain separate copies of the module data, including the array that is of concern to you.

View solution in original post

0 Kudos
2 Replies
mecej4
Honored Contributor III
951 Views

Please build and run the DLL_Shared_Data example in the compiler installation folders. If you do not configure and build the code correctly, what will happen is that both the DLL and the EXE contain separate copies of the module data, including the array that is of concern to you.

0 Kudos
aurora
Beginner
950 Views

That example was just perfect for my purpose. The only thing I had to do was to use the !DEC$ ATTRIBUTES DLLEXPORT statement below every variable I needed. Now the code works without problems.

Thanks a lot.

0 Kudos
Reply