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.

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. Also, you do not have to worry about exactly which routines you need to include — the Linker takes care of that for you.

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.

A static library is a collection of source and object code defined in the FileView pane. 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.

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.

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

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, use Step to Cursor to reach the cursor position, or use the step controls on the Debug toolbar.

Using Static Libraries

You add static libraries to a main project in the visual development environment with the Add to Project, Insert Files option in the Project menu. You can enter the path and library name in the Insert Files into Project dialog box with a .LIB extension on the name. If you are using a foreign 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.

For an example of a static library project, see the Visual Fortran Samples folder ...\DF98\Samples\Scigraph\Scigraph, which creates a static library.

To create a static library from the command line, use the /c compiler option to suppress linking and use the LIB command (see Managing Libraries with LIB).

To create a static library from the visual development environment, specify the Fortran Static Library project type.