Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 9/08/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Use Fortran Static Library Projects

Fortran static libraries (.LIB) are blocks of code compiled and kept separate from the main part of your program. The Fortran static library is one of the Fortran project types.

To create a static library from the integrated development environment (IDE), select the Static Library project type. To create a static library from the command line, use the c option to suppress linking and use the LIB command.

NOTE:

When compiling a static library from the command line, include the c option to suppress linking. Without this option, the compiler generates an error because the library does not contain a main program.

When you create a static library, you are asked to specify whether you want to prevent the insertion of link directives for default libraries. By default, this checkbox is selected, which means insertion of link directives is prevented. Select this option if you plan to use this static library with other Fortran projects. The option prevents the static library from specifying a version of the Fortran runtime library. When the static library is linked with another Fortran project, the Fortran runtime library choice in the other Fortran project is used for the static library as well.

You may decide against selecting this option if you plan to use this static library with C/C++ projects. If you do select it, you need to explicitly name the Fortran runtime library to use in the Linker Additional Dependencies property. You can change your selection after creating the project using the Fortran Disable Default Library Search Rules property.

A static library is a collection of source and object code defined in the Solution Explorer window. The source code is compiled when you build the project. The object code is assembled into a .LIB file without going through a linking process. The name of the project is used as the name of the library file by default. Static libraries offer important advantages in organizing large programs and in sharing routines between several programs. These libraries contain only subprograms, not main programs. A static library file has a .LIB extension and contains object code.

When you associate a static library with a program, any necessary routines are linked from the library into your executable program when it is built. Static libraries are usually kept in their own directories. If you use a static library, only those routines actually needed by the program are incorporated into the executable image (.EXE). This means that your executable image will be smaller than if you included all the routines in the library in your executable image. The Linker determines which routines to include.

Because applications built with a static library all contain the same version of the routines in the library, you can use static libraries to help keep applications current. When you revise the routines in a static library, you can easily update all the applications that use it by relinking the applications.

If you have a library of substantial size, you should maintain it in a dedicated directory. Projects using the library access it during linking.

When you link a project that uses the library, selected object code from the library is linked into that project's executable code to satisfy calls to external procedures. Unnecessary object files are not included.

To debug a static library, you must use a main program that calls the library routines. Both the main program and the static library should have been compiled using the debug option. After compiling and linking is completed, open the Debug menu and choose Go to reach breakpoints, or use the step controls on the Debug toolbar.

Use Static Libraries

To add static libraries to a main project in the IDE, use the Add Existing Item... option in the Project menu. You can enter the path and library name with a .LIB extension in the dialog box that appears. If you are using a makefile, you must add the library by editing the makefile for the main project. If you are building your project from the command line, add the library name with a .LIB extension and include the path specification if necessary.