Absoft Pro Fortran
Absoft Pro Fortran compilers offer several flexible options to create DLLs and to deal with name-mangling and calling conventions.
To indicate that a subroutine should conform to the standard calling convention, you add the STDCALL qualifier to the subroutine declaration. For example:
stdcall subroutine MySub(argument1, argument2)
When a Fortran procedure is declared with the standard calling convention (STDCALL), Absoft Pro Fortran mangles its name. The name-mangling performed by Pro Fortran prefixes the procedure name with an underscore and appends an at symbol (@) followed by the size of the stack (in bytes) to the end of the name. The size of the stack is equal to 4 times the number of arguments in the subroutine. Subroutine MySub has 2 arguments, so the mangled name will be:
_MySub@8
Having to use this name to call our DLL procedure would be awful in most languages, and illegal in Visual Basic. To solve this problem, you can create an accessory file (with the extension .als) for the linker containing aliases for the mangled names. In this case, the file could contain a single line:
_MySub@8 MySub
This file is used later to tell the linker that subroutine _MySub@8 will be known externally as MySub.
A DLL file can contain many subroutines. With Absoft Pro Fortran, you use another file (with the extension .xps) to indicate the name of the Fortran procedures that will be exported to the DLL. In this case, the exports file could contain only one line:
MySub
To create a DLL, you use the /dll switch with Absoft’s linker. The following command-lines would compile and link MySub.f90 (containing subroutine MySub) into MySub.dll:
f90 –c MySub.f90
lnk /dll MySub.obj /exports:MySub.xps /aliases:MySub.als absRT0.lib fmath.lib f90math.lib
The /exports switch loads the file with the list of procedures to export into MySub.dll. The /aliases switch loads the aliases file with the external (public) name of the subroutine.