Visible to Intel only — GUID: GUID-816947AF-F36B-4F81-B827-531399A60D3E
Visible to Intel only — GUID: GUID-816947AF-F36B-4F81-B827-531399A60D3E
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
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 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
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 macOS
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
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:
Use option c to generate object files from the source files:
ifort /c my_source1.f90 my_source2.f90
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
Compile and link your project with your new library:
ifort main.f90 my_lib.lib