DIGITAL Fortran 90
User Manual for
DIGITAL UNIX Systems


Previous Contents Index

2.5.1 Specifying Additional Object Libraries

You can control the libraries to be searched with these methods:

2.5.2 Specifying Types of Object Libraries

External references found in an archive library result in the referenced routine being included in the resulting executable program file at link time.

External references found in a shared object library result in a special link to that library being included in the resulting executable program file, instead of the actual routine itself. When you run the program, this link gets resolved by either using the shared library in memory (if it already exists) or loading it into memory from disk.

Certain f90 options influence whether ld searches for an archive ( .a ) or shared object ( .so ) library on the standard list of f90 libraries, as well as any additional libraries specified by using the -l string or -l dir options:

2.5.3 Specifying Shared Object Libraries

When you link your program with a shared library, all symbols must be referenced before ld searches the shared library. You should always specify libraries at the end of the f90 command line, after all file names. Unless you specify the -non_shared option, shared libraries will be searched before the corresponding archive libraries.

For instance, the following command generates an error if the file rest.o references routines in the library libx :


% f90 -call_shared test.f -lX rest.o

The correct command specifies the library at the end of the line, as follows:


% f90 -call_shared test.f rest.o -lX

Link errors can occur with symbols that are defined twice, as when both an archive and a shared object library are specified on the same command line. In general, specify any archive libraries after the last file name, followed by any shared libraries at the end of the command line.

Before you reference a shared library at run time, it must be installed. For further information on creating or installing a shared library, see Section 2.6.

2.6 Creating Shared Libraries

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

You can specify multiple source and object files when creating a shared library by using the f90 command.

2.6.1 Creating a Shared Library with a Single f90 Command

You can create a shared library ( .so ) file with a single f90 command:


% f90 -shared  octagon.f90

The -shared 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 .

2.6.2 Creating a Shared Library with f90 and ld Commands

You first must create the .o file, such as octagon.o in the following example:


% f90 -O3 -c octagon.f90

The file octagon.o is then used as input to the ld command to create the shared library named octagon.so :


% ld -shared -no_archive octagon.o \
          -lUfor -lfor -lFutil -lm -lots -lc

2.6.3 Choosing How to Create a Shared Library

Consider the following when deciding whether to use a single f90 command ( -c omitted) or both the f90 ( -c present) and ld commands to create a shared library:

In addition to the options shown in Section 2.6.1 and Section 2.6.2, certain other ld options may be needed. For instance, to optimize shared library startup, use the -update_registry and -check_registry options, which preassigns a starting address in virtual memory to a shared library using the file /usr/shlib/so_locations .

For additional information on the relevant ld options, see the ld(1) reference page.

For more information about the standard list of libraries used by DIGITAL Fortran 90, see Section 2.5.

2.6.4 Shared Library Restrictions

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

For other restrictions imposed by the operating system, see the DIGITAL UNIX Programmer's Guide.

2.6.5 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:

For complete information on installing shared libraries, see the DIGITAL UNIX Programmer's Guide.


Previous Next Contents Index