Lahey/GNU Fortran

Building Fortran DLLs

When you create a Fortran DLL, you must indicate the procedures that you want to export from the DLL with the !GCC$ ATTRIBUTES DLLEXPORT attribute. The procedures may be subroutines or functions. When mixing languages, the function results must be of type default INTEGER, REAL, or LOGICAL. The case of the name as it appears in the !GCC$ ATTRIBUTES DLLEXPORT and !GCC$ ATTRIBUTES dllimport statements is preserved for external resolution except when the -ml lf90 option is used; within the Fortran code the case is ignored, i.e., Foo is the same as FOO. Note that the compiler allows you to build your DLL from multiple .OBJ files.

Example code

function half(x) !GCC$ ATTRIBUTES dllexport :: half ! name is case-sensitive integer :: half integer :: x half = x/2 end

The code must be compiled using the -ML option. When the -dll option specified, a DLL is created and a Microsoft-compatible import library is generated.

Example build command

LGF -dll -win -ml half.f90

The above command creates the files half.dll and half.a which are compatible with Microsoft Visual C.