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

DLL export naming confusion...

anthonyrichards
New Contributor III
613 Views
I use CFV 6.6c. In order for a third-party application to access an application of mine written in FORTRAN, I must supply it in the form of a DLL containing a subroutine with an exported lower case name 'usersub'. That is the routine that the third-party app. looks for (I think it is C-based).The standard compiler directive DLLEXPORT produces a DLL with 2 exports for a subroutine named USERSUB. These are USERSUB and_USERSUB@8 (The subroutine takes two arguments). When building the DLL, I have to include a Third-party .OBJ containing routines that it requires to be present, one of whose names (cvsetupprocedure) is exported using '/export: cvsetupprocedure' added to the project's linker step. I would like to know two things
1) How can I achieve a lower-case exported name 'usersub' using compiler directives? (I achieved this by using /export:usersub=_USERSUB@8 as a linker stage addition, but am not sure why it worked!)
2) Why does the listing produced by DUMPBIN /SYMBOLS carried out seperately on the Dynamic-link library's .DLL and .LIB files produce names which sometimes differ by a leading underscore? I include sample listing below.(p.s., for some reason, when I type_USERSUB@8 itis almost always automatically underlined in the above text, when it should only have a leading underscore!)
C:F90DF ewbeamsUSERSUBRelease>DUMPBIN USERSUB.lib /EXPORTS
Microsoft COFF Binary File Dumper Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

Dump of file USERSUB.lib
File Type: LIBRARY
Exports
ordinal name
_USERSUB@8
_cvsetupprocedure
usersub
Summary
C6 .debug$S
14 .idata$2
14 .idata$3
4 .idata$4
4 .idata$5
C .idata$6
C:F90DF ewbeamsUSERSUBRelease>DUMPBIN USERSUB.DLL /EXPORTS
Microsoft COFF Binary File Dumper Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

Dump of file USERSUB.DLL
File Type: DLL
Section contains the following exports for usersub.dll
0 characteristics
43D608CF time date stamp Tue Jan 24 11:00:31 2006
0.00 version
1 ordinal base
3 number of functions
3 number of names
ordinal hint RVA name
1 0 00001000 _USERSUB@8
2 1 00001020 cvsetupprocedure
3 2 00001000 usersub
Summary
1000 .data
1000 .rdata
1000 .reloc
1000 .text
1000 .trace
C:F90DF ewbeamsUSERSUBRelease>

Message Edited by anthonyrichards on 01-24-200604:28 AM

Message Edited by anthonyrichards on 01-24-2006 04:29 AM

Message Edited by anthonyrichards on 01-24-2006 04:30 AM

0 Kudos
3 Replies
Steven_L_Intel1
Employee
613 Views
!DEC$ ATTRIBUTES DLLEXPORT, ALIAS:"usersub" :: usersub

The Microsoft tools sometimes hide the leading underscore. I agree it is frustrating.
0 Kudos
anthonyrichards
New Contributor III
613 Views
Thanks, Steve. After finally getting my application to start with a call to my DLL containing the exported symbol 'usersub' from the third-party app., I found that when I finally exited from my application by returning from the 'usersub' routine, the third party app. crashed with an access error. After various attempts at 'voodoo' to solve the problem(!!), Igot the feeling that this might be due to C/Fortran stack handling problems, so I played around with !DEC$ directives until I hit on one that worked and the third party app. stopped crashing on return from my app. Here is what I found worked:
!DEC$ ATTRIBUTES REFERENCE, C :: USERSUB
!DEC$ ATTRIBUTES DLLEXPORT :: USERSUB
Abonus is that this appears to automatically produce a lower-case exported name in the DLL that isproduced.
0 Kudos
Steven_L_Intel1
Employee
613 Views
Yup - if the calling application expects the C calling interface, your solution is good. I recommend adding the alias anyway as CVF is supposed to be adding an underscore. I've seen some situations where it doesn't.
0 Kudos
Reply