Executables generated using static libraries are no different than executables generated from individual source or object files. Static libraries are not required at runtime, so you do not need to include them when you distribute your executable. At compile time, linking to a static library is generally faster than linking to individual source files.
When compiling a static library from the ifort command line, include the -c (Linux OS and Mac OS X) or /c (Windows OS) compiler option to suppress linking. Without this option, the compiler generates an error because the library does not contain a main program.
To build a static library (Linux OS):
Use the -c option to generate object files from the source files:
ifort -c my_source1.f90 my_source2.f90 my_source3.f90
Use the GNU ar tool to create the library file from the object files:
ar rc my_lib.a my_source1.o my_source2.o my_source3.o
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
To build a static library (Mac OS X):
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
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
To build a static library (Windows OS):
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:
Use the /c option to generate object files from the source files:
ifort /c my_source1.f90 my_source2.f90
Use the Microsoft LIB tool to create the library file from the object files:
lib /out:my_lib.lib my_source1.obj my_source2.obj
Compile and link your project with your new library:
ifort main.f90 my_lib.lib
Copyright © 1996-2010, Intel Corporation. All rights reserved.