Building Dynamic-Link Libraries

When you first create a DLL, you follow the general steps described in Defining Your Project. Select Fortran Dynamic-Link Library as the project type when you create a new project in the Microsoft visual development environment.

To debug a DLL, you must use a main program that calls the library routines (or references the data). From the Project Settings menu, choose the Debug tab. A dialog box is available for you to specify the executable for a debug session.

To build the DLL from the Microsoft visual development environment:

  1. A Fortran DLL project is created like any other project, but you must specify Fortran Dynamic-Link Library as the project type (see Defining Your Project).
  2. Add files to your Fortran DLL project (see Defining Your Project). Include the DLL Fortran source that exports procedures or data as a file in your project.
  3. If your DLL exports data, for both the DLL and any image that references the DLL's exported data, consistently specify the project settings options in the Fortran Data category. In the Fortran Data compiler option category, specify the appropriate values for Common Element Alignment (common block data) and Structure Element Alignment (structures in a module). This sets the /alignment option, which specifies whether padding is needed to ensure that exported data items are naturally aligned.

    For example, in the case of a common block containing four-byte variables, in the Project Setting dialog box you might specify:

  4. If you need to specify linker options, use the Linker tab of the Project Settings dialog box.
  5. Build your Fortran DLL project.

    The Microsoft visual development environment automatically selects the correct linker instructions for loading the proper run-time library routines (located in a DLL themselves). Your DLL is created as a multithread-enabled library. An import library (.LIB) is created for use when you link images that reference the DLL.

To build the DLL from the command line:

  1. If you build a DLL from the command line or use an exported makefile, you must specify the /dll option. For example, if the Fortran DLL source code is in the file f90arr.f90, use the following command line:
    
      DF /dll f90arr.f90 

    This command creates:

    If you also specify /exe:file or /link /out:file, you name a .DLL rather than an .EXE file (the default file extension becomes projectname.DLL instead of projectname.EXE)

    The /dll option selects as the default the DLL run-time libraries to support multithreaded operation.

  2. If your DLL will export data, the procedures must be compiled and linked consistently. Consistently use the same /alignment option for the DLL export procedure and the application that references (imports) it. The goal is to specify padding to ensure that exported data items are naturally aligned, including common block data items and structure element alignment (structures in a module).
  3. If you need to specify linker options, place them after the /link option on the DF command line.
  4. Build the application.

    For example, if your DLL exports a common block containing four-byte variables, you might use the following command line (specify the /dll option):

      DF /align:commons /dll dllfile.for
    

    The /dll option automatically selects the correct linker instructions for loading the proper run-time library routines (located in a DLL themselves). Your DLL is created as a multithread-enabled library.

For more information, see: