Intel® Fortran Compiler 17.0 Developer Guide and Reference

Creating Shared Libraries

This topic applies to Linux* and OS X*.

Shared libraries, also referred to as dynamic libraries, are linked differently than static libraries. At compile time, the linker insures that all the necessary symbols are either linked into the executable, or can be linked at runtime from the shared library. Executables compiled from shared libraries are smaller, but the shared libraries must be included with the executable to function correctly. When multiple programs use the same shared library, only one copy of the library is required in memory.

To create a shared library from a Fortran source file, process the files using the ifort command:

Creating a Shared Library

There are several ways to create a shared library.

You can create a shared library file with a single ifort command:

ifort -shared -fpic octagon.f90 (Linux*)
ifort -dynamiclib octagon.f90 (OS X*)

The -shared or -dynamiclib option is required to create a shared library. The name of the source file is octagon.f90. You can specify multiple source files and object files.

Because the -o option was omitted, the name of the shared library file is octagon.so (Linux*) or octagon.dylib (OS X*).

You can use the -static-intel option to force the linker to use the static versions of the Intel-supplied libraries.

You can also create a shared library file with a combination of ifort and ld (Linux*) or libtool (OS X*) commands:

First, create the .o file, such as octagon.o in the following example:

ifort -c -fpic octagon.f90

The file octagon.o is then used as input to the ld (Linux*) or libtool (OS X*) command to create the shared library. The following example shows the command to create a shared library named octagon.so on a Linux* operating system:

ld -shared octagon.o \
     -lifport -lifcoremt -limf -lm -lcxa \
     -lpthread -lirc -lunwind -lc -lirc_s

Note the following:

It is recommended that you review the output of the -dryrun command to find the names of all the libraries used, to be able to specify them correctly.

If you are using the ifort command to link, you can use the -Qoption command to pass options to the ld linker. (You cannot use -Qoption on the ld command line.)

For more information on relevant compiler options, see the Compiler Options reference.

See also the ld(1) reference page.

Shared Library Restrictions

When creating a shared library with ld, be aware of the following restrictions:

Installing Shared Libraries

Once the shared library is created, it must be installed for private or system-wide use before you run a program that refers to it: