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

ID 767251
Date 11/07/2023
Public

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

Document Table of Contents

Create Static Libraries

Executables generated using static libraries are no different than executables generated from individual source or object files. Because static libraries are not required at runtime, you do not need to include them when you distribute your executable. Linking to a static library is generally faster than linking to individual object files.

When building objects for a static library from the ifort command line, include option c to suppress linking. Without this option, the linker will run and generate an error because the object is not a complete program.

Build a Static Library on Linux

  1. Use the c option to generate object files from the source files:

    ifort -c my_source1.f90 my_source2.f90 my_source3.f90
  2. Use the Intel® xiar tool to create the library file from the object files:

    xiar rc my_lib.a my_source1.o my_source2.o my_source3.o
  3. Compile and link your project with your new library:

    ifort main.f90 my_lib.a

If your library file and source files are in different directories, use the -Ldir option to indicate where your library is located:

ifort -L/for/libs main.f90 my_lib.a

Build a Static Library on Windows

To build a static library from the integrated development environment (IDE), select the Fortran Static Library project type.

To build a static library using the command line:

  1. Use option c to generate object files from the source files:

    ifort /c my_source1.f90 my_source2.f90
  2. Use the Intel® xilib tool to create the library file from the object files:

    xilib /out:my_lib.lib my_source1.obj my_source2.obj
  3. Compile and link your project with your new library:

    ifort main.f90 my_lib.lib