- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I need to create and use dynamic-link library (DLL) for Fortran application using Compaq Visual Fortran 6.6. The following code works just fine:
PROGRAM AMAIN1
IMPLICIT NONE
REAL(8):: A,B,S
A = 1D0
B = 2D0
CALL SUBRO1(A,B,S)
PRINT*, 'S = ', S
END PROGRAM AMAIN1
SUBROUTINE SUBRO1(A,B,S)
!DEC$ ATTRIBUTES DLLEXPORT :: SUBRO1
IMPLICIT NONE
REAL(8):: A,B,S
S = A + B
RETURN
END SUBROUTINE SUBRO1
The result is correct:
S = 3.00000000000000
Press any key to continue
However, if I implement the same algorithm using the module, I get inconsistent result (i.e. zero):
PROGRAM AMAIN2
USE MODUL2
A = 1D0
B = 2D0
CALL SUBRO2
PRINT*, 'S = ', S
END PROGRAM AMAIN2
MODULE MODUL2
IMPLICIT NONE
REAL(8):: A,B,S
END MODULE MODUL2
SUBROUTINE SUBRO2
!DEC$ ATTRIBUTES DLLEXPORT :: SUBRO2
USE MODUL2
S = A + B
RETURN
END SUBROUTINE SUBRO2
The result is incorrect:
S = 0.000000000000000E+000
Press any key to continue
As can be seen above, DLL contains only subprogram in both cases (SUBRO1 and SUBRO2, respectively). I have built DLL and LIB files from the visual development environment. The second case (with the use of module) represents the structure of my large source-code so I need to resolve this issue. Any advice would be greatly appreciated.
BTW, the same algorithm without using the DLL works well and gives correct result:
PROGRAM AMAIN3
USE MODUL3
A = 1D0
B = 2D0
CALL SUBRO3
PRINT*, 'S = ', S
END PROGRAM AMAIN3
MODULE MODUL3
IMPLICIT NONE
REAL(8):: A,B,S
END MODULE MODUL3
SUBROUTINE SUBRO3
USE MODUL3
S = A + B
RETURN
END SUBROUTINE SUBRO3
The result is correct:
S = 3.00000000000000
Press any key to continue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I was able to log in to Bakhbergen's PC and eventually figured out the problem.
In CVF 6.6C (and the later Intel compilers), when you USE a module that has a DLLEXPORT directive, that turns into a DLLIMPORT. But it wasn't always this way, and the version he has doesn't have that behavior. Before that change (which my memory says I lobbied for), you had to supply a separately compiled .mod where the source had DLLIMPORT instead of DLLEXPORT. When I did this, the program worked. I don't remember exactly which update had this change.
So what he needs to do is have two versions of MODUL2.f90, one with DLLEXPORT and one with DLLIMPORT. The DLLEXPORT version gets built into the DLL. The DLLIMPORT version would just be compiled (/c) and only the .mod used, not the ,obj, when linking the main program. Messy, I know, which is why we changed it.
We also discussed why he is using that specific old version, and I understand the reasons (which I will not go into further here.)
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please find attached the zipped amain2.map and cmd.docx files.
The following command lines have been run:
f90 /MD /compile_only modul2.f90
! Creates: 1) modul2.obj 2) modul2.mod
f90 /LD subro2.f90 modul2.obj
! Creates: 1) subro2.lib 2) subro2.exp 3) subro2.dll
f90 /MD amain2.f90 modul2.obj subro2.lib /link /map & amain2
! Creates 1) amain2.map 2) amain2.lib 3) amain2.exp 4) amain2.exe
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oh, I see!
Don't include modul2.obj when you link amain2, as that gets you a local copy of the module.
Use:
df /MD amain2.f90 subro2.lib & amain2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Microsoft Windows [Version 10.0.17134.523]
(c) Корпорация Майкрософт (Microsoft Corporation), 2018. Все права защищены.
C:\Users\bakhb_000>d:
D:\>cd temporaryfolder/ivfcvfforum4
D:\TemporaryFolder\IVFCVFFORUM4>df /MD /compile_only modul2.f90
Compaq Visual Fortran Optimizing Compiler Version 6.6
Copyright 2001 Compaq Computer Corp. All rights reserved.
modul2.f90
D:\TemporaryFolder\IVFCVFFORUM4>df /LD subro2.f90 modul2.obj
Compaq Visual Fortran Optimizing Compiler Version 6.6
Copyright 2001 Compaq Computer Corp. All rights reserved.
subro2.f90
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
/entry:_DllMainCRTStartup@12
/ignore:505
/debugtype:cv
/debug:minimal
/pdb:none
C:\Users\BAKHB_~1\AppData\Local\Temp\objFD7E.tmp
modul2.obj
dfordll.lib
msvcrt.lib
dfconsol.lib
dfport.lib
kernel32.lib
/out:subro2.dll
/dll
Creating library subro2.lib and object subro2.exp
D:\TemporaryFolder\IVFCVFFORUM4>df /MD amain2.f90 subro2.lib & amain2
Compaq Visual Fortran Optimizing Compiler Version 6.6
Copyright 2001 Compaq Computer Corp. All rights reserved.
amain2.f90
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
/subsystem:console
/entry:mainCRTStartup
/ignore:505
/debugtype:cv
/debug:minimal
/pdb:none
C:\Users\BAKHB_~1\AppData\Local\Temp\obj2C8D.tmp
subro2.lib
dformd.lib
msvcrt.lib
dfconsol.lib
dfport.lib
kernel32.lib
/out:amain2.exe
obj2C8D.tmp : error LNK2001: unresolved external symbol _MODUL2_mp_A
obj2C8D.tmp : error LNK2001: unresolved external symbol _MODUL2_mp_B
obj2C8D.tmp : error LNK2001: unresolved external symbol _MODUL2_mp_S
amain2.exe : fatal error LNK1120: 3 unresolved externals
'amain2' is not recognized as an internal or external command,
operable program or batch file.
D:\TemporaryFolder\IVFCVFFORUM4>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Out of curiosity, what happens if you put the module code in modul2.f90 inside subro2.f90? There is really no reason to put it in a separate file. I don't have df, but with ifort I did this:
ifort /MD /dll subro2.f90
ifort /MD amain2.f90 subro2.lib
You could try this (with df not ifort) and see what it gives.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please show the output of:
dumpbin -exports subro2.dll
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I know that wasn't addressed to me, Steve, but this is what I see:
Microsoft (R) COFF/PE Dumper Version 8.00.50727.762
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file subro2.dll
File Type: DLL
Section contains the following exports for subro2.dll
00000000 characteristics
5C3D1701 time date stamp Tue Jan 15 12:10:57 2019
0.00 version
1 ordinal base
4 number of functions
4 number of names
ordinal hint RVA name
1 0 00003348 MODUL2_mp_A
2 1 00003350 MODUL2_mp_B
3 2 00003358 MODUL2_mp_S
4 3 00001000 SUBRO2
Summary
1000 .data
1000 .rdata
1000 .reloc
1000 .text
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
gib, that's what I would expect to see. But I have to think that Bakhbergen is doing something we're not seeing. I know that by the time of CVF 6.6 (interesting that none of the updates were installed) this absolutely would have worked. Heck, there was a sample that relied on it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is very odd.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, gib. This simple program represents the structure of our large source-code with 100+ subprograms (subroutines and functions). In our case module is used for declaring a large number of global variables and arrays that can be made available within the main program and any routines we choose.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Bakhbergen, I'm still curious to see the result of that small change with this tiny example.
What does dumpbin give?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I hope that this compiler installed on my laptop is working properly.
When I installed Compaq Visual Fortran 6.6 under Windows 10, I did the following:
(1) Open the CD with explorer;
(2) Go to folder x86;
(3) Set file mode of (x86/setup.exe) to run in Compatibility Mode with XP;
(4) execute the setup.exe located inside folder: x86/setup.exe;
(5) Located the file MSDev98\Bin\DFDEV.EXE Set the File Mode to run in Compatibility Mode with XP;
(6) You can apply all updates as usual;
(7) If it fails to run, make sure that the compatibility mode DFDEV.EXE is set to Compatibility Mode with XP.
After Avast antivirus’s attack I added Microsoft (R) Developer Studio (C:\Program Files\Microsoft Visual Studio\Common\MSDEV98\BIN\Dfdev.exe) into Do Not Disturb Mode.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
gib, I tried changing as per your instruction and making other similar alterations but it didn't work. Would you like to send me anything on that? Sorry my response may be delayed because I live on the other side of the Earth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I can't really help because I no longer have the CVF compiler. What did dumpbin give? Do this:
dumpbin -exports subro2.dll > dumpbin.out
and post dumpbin.out here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Microsoft Windows [Version 10.0.17134.523]
(c) Корпорация Майкрософт (Microsoft Corporation), 2018. Все права защищены.
C:\Users\bakhb_000>D:
D:\>CD TemporaryFolder/IVFCVFFORUM7
D:\TemporaryFolder\IVFCVFFORUM7>df /MD /compile_only modul2.f90
Compaq Visual Fortran Optimizing Compiler Version 6.6
Copyright 2001 Compaq Computer Corp. All rights reserved.
modul2.f90
D:\TemporaryFolder\IVFCVFFORUM7>df /LD subro2.f90 modul2.obj
Compaq Visual Fortran Optimizing Compiler Version 6.6
Copyright 2001 Compaq Computer Corp. All rights reserved.
subro2.f90
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
/entry:_DllMainCRTStartup@12
/ignore:505
/debugtype:cv
/debug:minimal
/pdb:none
C:\Users\BAKHB_~1\AppData\Local\Temp\obj2491.tmp
modul2.obj
dfordll.lib
msvcrt.lib
dfconsol.lib
dfport.lib
kernel32.lib
/out:subro2.dll
/dll
Creating library subro2.lib and object subro2.exp
D:\TemporaryFolder\IVFCVFFORUM7>df /MD amain2.f90 modul2.obj subro2.lib & amain2
Compaq Visual Fortran Optimizing Compiler Version 6.6
Copyright 2001 Compaq Computer Corp. All rights reserved.
amain2.f90
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
/subsystem:console
/entry:mainCRTStartup
/ignore:505
/debugtype:cv
/debug:minimal
/pdb:none
C:\Users\BAKHB_~1\AppData\Local\Temp\obj53DE.tmp
modul2.obj
subro2.lib
dformd.lib
msvcrt.lib
dfconsol.lib
dfport.lib
kernel32.lib
/out:amain2.exe
Creating library amain2.lib and object amain2.exp
S = 0.000000000000000E+000
D:\TemporaryFolder\IVFCVFFORUM7>dumpbin -exports subro2.dll
Microsoft (R) COFF Binary File Dumper Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
Dump of file subro2.dll
File Type: DLL
Section contains the following exports for subro2.dll
0 characteristics
5C3E4EF0 time date stamp Wed Jan 16 03:21:52 2019
0.00 version
1 ordinal base
5 number of functions
5 number of names
ordinal hint RVA name
1 0 00003040 MODUL2_mp_A
2 1 00003038 MODUL2_mp_B
3 2 00003030 MODUL2_mp_S
4 3 00001000 SUBRO2
5 4 00001000 _SUBRO2@0
Summary
1000 .data
1000 .rdata
1000 .reloc
1000 .text
D:\TemporaryFolder\IVFCVFFORUM7>
- 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
D:\TemporaryFolder\IVFCVFFORUM7>df /LD subro2.f90 modul2.obj
I think Steve suggested /MD. Shouldn't the following be the command to make the DLL?
df /MD /dll subro2.f90 modul2.f90
This is the command line I used (with ifort in place of df).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve, gib, your time and effort is greatly appreciated. Would it be convenient for you if I give a remote desktop permission to you? I have to go to work in the morning so I need to have a rest. Have a good day.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I recommend that Steve logs on to your machine, since he's forgotten more than I'll ever know about Fortran.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Bakhbergen, apart from all that has been said in this thread, please note that applying the last update to CVF6.6C, i.e, an update that would bring your installation to Compaq Visual Fortran 6.6-4088-47D3B (the output of df /what), would still keep your software exposed to the serious bug mentioned in https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/274046 .
I think that you should give serious consideration to switching to (or at least verifying with) a recent compiler (Ifort, Gfortran, etc.) before accepting the results from your application program.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I was able to log in to Bakhbergen's PC and eventually figured out the problem.
In CVF 6.6C (and the later Intel compilers), when you USE a module that has a DLLEXPORT directive, that turns into a DLLIMPORT. But it wasn't always this way, and the version he has doesn't have that behavior. Before that change (which my memory says I lobbied for), you had to supply a separately compiled .mod where the source had DLLIMPORT instead of DLLEXPORT. When I did this, the program worked. I don't remember exactly which update had this change.
So what he needs to do is have two versions of MODUL2.f90, one with DLLEXPORT and one with DLLIMPORT. The DLLEXPORT version gets built into the DLL. The DLLIMPORT version would just be compiled (/c) and only the .mod used, not the ,obj, when linking the main program. Messy, I know, which is why we changed it.
We also discussed why he is using that specific old version, and I understand the reasons (which I will not go into further here.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Well done, Steve!
![](/skins/images/C4F7392A5C68ACA60290C9576F107044/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page