- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can ignore the linker warnings (they are not errors).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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_GLOBALINTEGER, 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_COL4. 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You'll also want to look at warning 1 which may be a coding error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page