Creating Shared Libraries

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 (Mac OS*)

 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.

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

You can use the -i-static 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 (Mac OS*) 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 (MacOS*) command to create the shared library. The following example shows the command to create a shared library named octagon.so on a Linux system:

ld -shared octagon.o \

     -lifport -lifcoremt -limf -lm -lcxa \

     -lpthread -lirc -lunwind -lc -lirc_s

Note the following:

It is probably a good idea to look at the output of the -dryrun command to find the names of all the libraries used so you can 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 shared libraries, see Creating Libraries.

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: