Using Intel® Visual Fortran to Create and Build Windows*-Based Applications

ID 757211
Date 7/23/2021
Document Table of Contents

Building Executables that Use DLLs

When you build the executable that imports the procedures or data defined in the DLL, you must link using the import library, check certain project settings or command-line options, and then build the executable.

To use the DLL from another image:

  1. Add the import .LIB file with its path and library name to the other image.

    In the integrated development environment, add the .LIB import library file to your project. In the Project menu, select Add Existing Item... . If the importing project and the DLL are in the same solution, you can add the DLL project as a dependency of the importing project instead.

    On the command line, specify the .LIB file on the command line.

    The import .LIB file contains information that your program needs to work with the DLL.

  2. If your DLL exports data, consistently use the same property page options in the Fortran Data category /align option as was used to create the DLL. In the Fortran Data category, specify the appropriate values for Common Element Alignment (common block data) and Structure Member Alignment (structures in a module). This sets the /align option, which specifies whether padding is needed to ensure that imported data items are naturally aligned.

  3. In the Project Property Pages dialog box, make sure the type of libraries specified is consistent with that specified for the Fortran DLL.

  4. If you need to specify linker options:

    • In the IDE, specify linker options in the Linker category.

    • On the ifort command line, place linker options after the /link option.

  5. Copy the DLL into your path.

    For an application to access your DLL, it must be located in a directory included in the PATH system environment variable or in the same directory as the executable. If you have more than one program accessing your DLL, you can keep it in a convenient directory identified in the environment variable PATH. If you have several DLLs, you can place them all in the same directory to avoid adding numerous directories to the path specification.

    You should log out and back in after modifying the system path.

  6. Build the image that references the DLL.

    When using the visual development environment:

    • Like building other projects in the integrated development environment, use the Build menu items to create the executable.

    When using the command line:

    • Specify the import library at the end of the command line.

    • If your DLL exports data that will be used by the application being built, specify the same /align options that were used to build the DLL.

    • If you are building a main application, omit the /dll option.

    • When building a Fortran DLL that references another DLL, specify the /dll option.

    For example, to build the main application from the command line that references 4-byte items in a common block defined in dllfile.dll:

ifort /align:commons mainapp.f90 dllfile.lib