Lahey/Fujitsu Fortran

Building Import Libraries

A Microsoft-compatible import library is automatically generated whenever LF95 is used to create a DLL. When an LF95 program that calls a DLL is linked, a Microsoft-compatible import library must be provided. Usually, the vendor that supplies the DLL will also provide a Microsoft-compatible import library. Additional information on import libraries can be found in Library Manager under the heading Creating import libraries.

Building import libraries from object files

If the user is building a non Fortran DLL on site for use with LF95, and a Microsoft-compatible import library is not created, an import library can be generated from the object files using LIB.EXE. Doing this entails making a definition file which contains the names of the exported procedures, and running LIB with the following command:

LIB /def:defile.def file1.obj file2.obj /out:implib.lib

defile.def is the name of the definition file.

file1.obj and file2.obj are object files that were used to build the DLL.

implib.lib is the name of the import library to be produced.

Lahey provides a utility MAKEDEF.EXE to generate definition files given a DLL. Alternatively, the DUMPBIN utility can be used to list exported symbols from the DLL; then the definition file can be created by hand. Note that any export that appears in the definition file must be present in the object file, otherwise an unresolved reference will occur when the LIB command is executed. If this happens, it is usually sufficient to remove the unresolved reference from the definition file.

Building import libraries when no object file is available

Occasionally, the situation occurs when only a DLL is available, without an import library or object files. If the user knows how to call the DLL procedure from Fortran, an import library can be generated using a stub program. A stub program is a skeleton that contains function or subroutine statements including any argument calling sequences, argument declarations, a DLL_EXPORT statement, and end statement, but no other source code - much like a procedure would appear inside an interface block. The stub file is compiled to create an LF95 object file, using an appropriate -ml option, and -c. Once the stub object file is created, the import library can be generated using the instructions in the preceding section. During execution of the LIB command, a warning concerning duplicate symbols may appear, if a non Microsoft convention is used, but it can be disregarded. Note that -ml lf95 should never be used to create import libraries from stubs. Code that calls the DLL should be compiled using the same -ml option that was used to compile the stub file. Note that the definition file that is used when creating the import library should only contain procedure names that appear in the stub file, otherwise unresolved references will occur when the LIB command is executed. An example of creating import libraries using stubs appears in the \Win32\Examples\Mix_Lang\BD subdirectory under the Fortran installation directory.

Building non Microsoft import libraries for Fortran DLLs

If the user wishes to build an import library for a Fortran DLL that is called from a language that does not accept Microsoft-compatible import libraries, the 3rd party language will usually provide a method of generating a compatible import library, such as Borland's IMPLIB.EXE. In some cases, the 3rd party linker may provide commands that enable DLL references to be resolved. Consult the documentation provided with the 3rd party compiler and tools for instructions on resolving references to DLL procedures.

Examples of how to build Fortran callable DLLs from non Fortran languages, and how to generate Microsoft compatible import libraries from non Microsoft object files reside in directories under the \Win32\Examples\Mix_Lang subdirectory under the Fortran installation directory.