Examples of the ifort Command

Compiling and Linking Multiple Files

The following ifort command compiles the Fortran free-format source files aaa.f90, bbb.f90, and ccc.f90. The command invokes the ld linker and passes the temporary object files to the linker, which it uses to produce the executable file a.out:

ifort aaa.f90 bbb.f90 ccc.f90

The following ifort command compiles all file names that end with .f. as Fortran fixed-format source. The linker produces the a.out file:

ifort *.f

Preventing Linking

The following ifort command compiles, but does not link, the free-format source file typedefs_1.f90, which contains a MODULE TYPEDEFS_1. The command creates files typedefs_1.mod and typedefs_1.o. The object file is retained automatically. Specifying the -c option  prevents linking:

ifort -c typedefs_1.f90

Renaming the Output File

The following ifort command compiles the free-format Fortran source files circle-calc.f90 and sub.f90 together:

ifort -c circle-calc.f90 sub.f90

The default optimization level -O2 applies to both source files during compilation. Because the -c option is specified, the object files are not passed to the linker. In this case, the named output files are the object files.

Like the previous command, the following ifort command compiles multiple source files:

ifort -o circle.out circle-calc.f90 sub.f90

Because the -c option was omitted, an executable program named circle.out is created.

Specifying an Additional Linker Library

The following ifort command compiles a free-format source file myprog.f90 using default optimization, and passes an additional library for the linker to search:

ifort myprog.f90 typedefs_1.o -lmylib

The file is processed at optimization level -O2 and then linked with the object file typedefs_1.o . The -lmylib option instructs the linker to search in the libmylib library for unresolved references (in addition to the standard list of libraries the ifort command passes to the linker).