View previous topic :: View next topic |
Author |
Message |
StamK
Joined: 12 Oct 2016 Posts: 159
|
Posted: Tue Jul 02, 2019 10:55 pm Post subject: Accesing module variables in a DLL |
|
|
It doesn't seem possible to access global variables in a module in a DLL.
Module (in a separate file, to be made as a DLL)
Code: |
!ftn95$free
MODULE TESTMOD
INTEGER*4 :: QT_NWIN = 99
END MODULE
|
Main program (separate file, loads previous DLL)
Code: |
!ftn95$free
program main
USE TESTMOD
SAVE
print*," QT_NWIN =", QT_NWIN
END
|
When linking, it says:
Code: |
WARNING the following symbols are missing:
MODULE TESTMOD
|
and when I run it, I can see that it has a random value of QT_NWIN. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7936 Location: Salford, UK
|
Posted: Wed Jul 03, 2019 6:57 am Post subject: |
|
|
When you compile a 32 bit module you get an interface in a .mod file and (usually) object code in a .obj file. Similarly for 64 bit code.
When you build something that accesses the module then the access at compile time is via a USE statement the uses the .mod file whilst the module .obj file is used at link time.
The process that you use to build a DLL is essentially the same as building an executable but there is no main program. A module still works via a .mod file and a .obj file. When linking you indicate that you want a DLL.
Routines that are in the DLL (within modules or not) are linked to the executable when it is loaded for running but there is no equivalent linking of module data. So the address of QT_NWIN in the DLL will not automatically be the same as the address of QT_NWIN in the executable. If you need to share data then the sharing must be done in some other way. |
|
Back to top |
|
|
StamK
Joined: 12 Oct 2016 Posts: 159
|
Posted: Wed Jul 03, 2019 9:16 am Post subject: |
|
|
Thanks for that. But why is there the warning
WARNING the following symbols are missing:
MODULE TESTMOD
Thanks |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7936 Location: Salford, UK
|
Posted: Wed Jul 03, 2019 9:19 am Post subject: |
|
|
I don't understand that. I would need a demonstration from your code and build process. |
|
Back to top |
|
|
StamK
Joined: 12 Oct 2016 Posts: 159
|
Posted: Wed Jul 03, 2019 9:36 am Post subject: |
|
|
If you copy the code above and make it into two files
testmod.for
app_main.for
and you do
ftn95 /windows /sparam 0 /zero /f2k /cfpp testmod.for
slink /3gb -dll -exportall testmod.obj
ftn95 /windows /sparam 0 /zero /f2k /cfpp app_main.for
slink /3GB testmod.dll app_main.obj
You will see the above warning |
|
Back to top |
|
|
StamK
Joined: 12 Oct 2016 Posts: 159
|
Posted: Wed Jul 03, 2019 9:46 am Post subject: |
|
|
I just realised the last line should be
slink /3GB app_main.obj testmod.dll
i.e. first the object file and then the DLL file, but the warning is still there. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7936 Location: Salford, UK
|
Posted: Wed Jul 03, 2019 10:39 am Post subject: |
|
|
I don't know exactly what is happening but there is nothing to export from this module. You can only export subprograms. You can't export variables. |
|
Back to top |
|
|
StamK
Joined: 12 Oct 2016 Posts: 159
|
Posted: Wed Jul 03, 2019 10:43 am Post subject: |
|
|
Even if you add a subroutine the same thing happens. It does work (i.e. you can call the subroutine), but you get this warning. I am hoping it is not an indication of something more sinister...
Code: |
!ftn95$free
MODULE TESTMOD
INTEGER*4 :: QT_NWIN = 99
contains
subroutine testmodinit
QT_NWIN = 100
end subroutine
END MODULE
|
|
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7936 Location: Salford, UK
|
Posted: Wed Jul 03, 2019 1:59 pm Post subject: |
|
|
I don't know why there is this report of a missing symbol.
If there are no runtime errors then I would treat it as benign.
The QT_NWIN in the main program will not have the same address as the QT_NWIN in the DLL and in my testing the QT_NWIN in the main program cannot be accessed.
So if you need to put a module into a DLL then you will have to do something special in order to access the module data from the executable. |
|
Back to top |
|
|
|