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

Sharing allocatable arrays and other data through a module in DLL

Reinaldo
Beginner
872 Views

This issue has come before, but I do not find a way to make it work.

I have a Fortran EXE and a Fortran DLL. I need to access allocatable arrays from both. I wrote this module:

MODULE MODFLOW_GLOBAL
INTEGER, ALLOCATABLE, DIMENSION(:) :: MFL_COL
INTEGER, ALLOCATABLE, DIMENSION(:) :: MFL_ROW
CHARACTER(200) :: MFL_FILENAME
!DEC$ ATTRIBUTES DLLEXPORT :: MFL_COL, MFL_ROW
!DEC$ ATTRIBUTES DLLEXPORT :: MFL_FILENAME

END MODULE MODFLOW_GLOBAL

I added this module as part of the DLL project. I then have the include directory where the correspoding MOD is in the EXE file. I allocate and initialize with data the arrays in the EXE code. Both the EXE and DLL projects compile OK.

However, the variables are not passing to the DLL properly. The values are not correct.

Couldyou help?

Thanks

Reinaldo

0 Kudos
8 Replies
Steven_L_Intel1
Employee
872 Views
I have attached a complete example VS2005 solution based on your module. Key points:

  • The EXE project adds the output folder from the DLL project as an additional INCLUDE directory
  • The EXE project specifies the DLL project as a dependent
  • The EXE project's run-time library type was changed to DLL to match the DLL project
  • I added a post-build step in the DLL project to copy the DLL to the EXE project folder
After reviewing this, let me know if you have questions.
0 Kudos
Reinaldo
Beginner
872 Views

Steve:

Thanks for your fast answer. In trying to load your solution I get a message stating that the project was created with a different version: I have Intel Visual Fortran version 10.1.021 and Visual Studio 2005 Version 8.0.50727.762 (SP.050727-7600).

Please advise,

Thanks,

Reinaldo

0 Kudos
Steven_L_Intel1
Employee
872 Views
Sorry, that was my error. Try this one.
0 Kudos
Reinaldo
Beginner
872 Views

Steve:

Thanks so much. This really helps. The program works as expected, but when I debug it and do a watch over the variables they say undefined pointer/array. That was the same I was getting in my code. Any idea why the debugger is not showing the correct values?

Other issue: When I use the variables in the main program (EXE) they are OK. But if I try to add a simple write or an assignment statement in the DLLI get this linkerror:

Linking...

1>Debugmf2005_dll.obj:warning : locally defined symbol __imp__MODFLOW_GLOBAL_mp_MFL_COL imported

1>Debugmf2005_dll.obj:warning : locally defined symbol __imp__MODFLOW_GLOBAL_mp_MFL_ROW imported

1>Debugmf2005_dll.obj:warning : locally defined symbol __imp__MODFLOW_GLOBAL_mp_MFL_FILENAME imported

Thanks for your support.

Reinaldo

0 Kudos
Steven_L_Intel1
Employee
872 Views
The debugging problem is an issue we're aware of and are working on.

You can ignore the linker warnings (they are not errors).
0 Kudos
Reinaldo
Beginner
872 Views

Steve, thanks.

I still have problems. Let me sumarize what I have:

1. DLL code that has a module as mentioned in onemy previous post.

MODULE

MODFLOW_GLOBAL

INTEGER, ALLOCATABLE, DIMENSION(:) :: MFL_COL

INTEGER, ALLOCATABLE, DIMENSION(:) :: MFL_ROW

CHARACTER(200) :: MFL_FILENAME

!DEC$ ATTRIBUTES DLLEXPORT :: MFL_COL, MFL_ROW

!DEC$ ATTRIBUTES DLLEXPORT :: MFL_FILENAME

END MODULE MODFLOW_GLOBAL

2. A EXE that Uses this module (the include directory is set to the one where the DLL code generates the mod file.

3. In the DLL main subroutine that is called from the exe main program(that Uses MODFLO_GLOBAL) I have these instructions:

write

(99911, *) ' MFL_FILENAME', MFL_FILENAME

write(99911, *) 'MFL_ROW'

write(99911, *) MFL_ROW

write(99911, *) 'MFL_col'

write(99911, *) MFL_COL

4. I try to compile the DLL but get these warnings and errors:

Warning1 Warning: A jump into a block from outside the block may have occurred. [110]C:PROYECTOSFLO-2D-MODFLOWMF2005.1_4srcmf2005_dll.f455
Warning2warning : locally defined symbol __imp__MODFLOW_GLOBAL_mp_MFL_COL importedDebugmf2005_dll.obj
Warning3warning : locally defined symbol __imp__MO DFLOW_GLOBAL_mp_MFL_ROW importedDebugmf2005_dll.obj
Warning4warning : locally defined symbol __imp__MODFLOW_GLOBAL_mp_MFL_FILENAME importedDebugmf2005_dll.obj
Error5 error LNK2001: unresolved external symbol __imp__MODFLOW_GLOBAL_mp_MFL_COLmf2005_dll.obj
Error6 error LNK2001: unresolved external symbol __imp__MODFLOW_GLOBAL_mp_MFL_ROWmf2005_dll.obj
Error7 error LNK2001: unresolved external symbol __imp__MODFLOW_GLOBAL_mp_MFL_FILENAMEmf2005_dll.obj
Error8 fatal error LNK1120: 3 unresolved externalsc:windowssystem32MODFLOWDLL.dll

Maybe the solution would be to create a DLL only with the module and use it from the main EXE and the DLL subroutines.

I would greatly appreciate your help.

Reinaldo


0 Kudos
Steven_L_Intel1
Employee
872 Views
I can't understand errors 5-7 - you should not get those. Can you attach a ZIP file with a sample project that shows this behavior?

You'll also want to look at warning 1 which may be a coding error.
0 Kudos
Reinaldo
Beginner
872 Views

Steve:

Sorry, you are right. I recoded to remove warning 1 and the other errors turned to warnigns, which is OK as I can run the program now.

Thanks again,

Reinaldo

0 Kudos
Reply