Building Executables that Use DLLs
- 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.
- If your DLL exports data, consistently use the same property page options in the Fortran Data category/alignoption 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/alignoption, which specifies whether padding is needed to ensure that imported data items are naturally aligned.
- In the Project Property Pages dialog box, make sure the type of libraries specified is consistent with that specified for the Fortran DLL.
- 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/linkoption.
- 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.
- Build the image that references the DLL.When using the visual development environment:
When using the command line:
- Like building other projects in the integrated development environment, use theBuildmenu items to create the executable.
For example, to build the main application from the command line that references 4-byte items in a common block defined in dllfile.dll:
- 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/alignoptions that were used to build the DLL.
- If you are building a main application, omit the/dlloption.
- When building a Fortran DLL that references another DLL, specify the/dlloption.
ifort /align:commons mainapp.f90 dllfile.lib