Compiling and Linking Multithread Programs

The support library DFORMT.LIB is a re-entrant library for creating statically linked multithread programs. The DFORMD.LIB library, which calls code in the shared DFORMD.DLL, is also re-entrant. Programs built with DFORMT.LIB do not share Fortran run-time library code or data with any dynamic-link libraries they call. You must link with DFORMD.LIB if you plan to call a DLL.

To build a multithread application that uses the Fortran run-time libraries, you must tell the linker to use a special version of the libraries. You can specify the /threads compiler option from the command line, or in the Microsoft visual development environment in the Project Settings dialog box, as described in the following paragraph.

A sample multithread project THREADS is included in the ...\DF98\SAMPLES\ADVANCED\WIN32\THREADS folder. To build this sample, open the project workspace file and choose Build All from the Build menu. Listed following are the steps for compiling and linking your own multithread program using the visual development environment.

To compile and link your multithread program:

  1. Create a new project. Choose the Project tab, then specify the project type. (The sample THREADS.F90 is a Fortran Windows project.)
  2. Add the file containing the source code to the project.
  3. From the Project menu, select Settings.
    The Project Settings dialog box appears.
  4. Choose the Fortran tab, Fortran Libraries category, and set the Use Multi-Threaded Library check box and set the Use Runtime Libraries to Static (DFORMT.LIB) or DLL (DFORMD.LIB).
  5. Create the executable file by choosing Build All from the Build menu.

The following steps describe how to compile and link the sample multithread program from the command line.

To compile and link the sample multithread program from the command line:

  1. Make sure the library files directory is specified in your LIB environment variable.
  2. Compile and link the program with the DF command-line option /threads.
    For example:
      DF /threads  MYTHREAD.F90
    

The /threads compiler option (automatically set when you specify a multithread application in the visual development environment) tells the linker to use DFORMT.LIB as a default library.

To compile and link the THREADS.F90 sample, the command is:

  DF /winapp /threads THREADS.F90

The /threads compiler option causes the linker to search the multithread library; the /winapp requests a Fortran Windows application.

Select the compiler options /libs=dll and /threads if you are using both multithread code and DLLs. You can use the /libs=dll and /threads options only with Fortran Console projects, not QuickWin applications.