Intel® Fortran Compiler 16.0 User and Reference Guide

Creating 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.

Building a static library (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:

    ar 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

Building a static library (OS X*)

  1. Use the following command line to generate object files and create the library file:

    ifort -o my_lib.a -staticlib mysource1.f90 mysource2.f90 mysource3.f90
  2. 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

Building a static library (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:

    lib /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