DIGITAL Fortran 90
User Manual for
DIGITAL
UNIX Systems
2.5.1 Specifying Additional Object Libraries
You can control the libraries to be searched with these methods:
- To specify additional object library file names for
ld
to search, use the
-l
string option at the end of the
f90
command line.
Each occurrence of the
-l
string option specifies an additional file name that is added
to the list of object libraries for
ld
to locate.
Table 2-4 shows the standard
f90
library file names that are searched by
ld
.
If you specify
-omp
or
-mp
(requests directed parallel processing), the
libots3
library is searched.
Which High Performance Fortran (HPF) library
is searched depends on which
f90
options are specified:
- If you specify
-pprof
and specify
-wsf
(or
-wsf 2
or greater),
libphpfp
is searched.
- If you omit
-pprof
and specify
-wsf
(or
-wsf 2
or greater),
libphpf
is searched.
- If you omit
-wsf
or specify
-wsf 1
,
libshpf
is searched.
The DIGITAL Fortran 90 kit provides both shared and archive libraries.
For a complete list of DIGITAL Fortran 90 Run-Time Library files, see f90(1).
- In addition to the
standard directories in which
ld
tries to locate the library file names, you can use the
-l
dir option to specify another directory.
Unlike the
-l
string option that adds an object library file name
for
ld
to search, the
-l
dir option adds an additional directory in which
ld
will look for library file names.
The standard
ld
directories are searched before directories specified by the
-l
dir option.
The following example specifies the additional
object library path
/usr/lib/mytest
:
% f90 simtest.f -L/usr/lib/mytest
|
For a list of the standard
ld
directories searched, see Section 3.48.
- You can specify the pathname and file name of an object library as
you would specify any file. Specifying each object library that resides
in special directories in this manner is an alternative to specifying
the library by using the
-l
string or
-l
dir option. Specifying the pathname and file name of an object
library can reduce the amount of searching the linker must do to locate
all the needed object files.
For instance, instead of specifying
the options
-l/usr/jones
and
-lfft
, this example specifies the directory path and file name of the
library file:
% f90 main.o more.o rest.o /usr/jones/libfft.a
|
In certain cases, you may need to specify the pathname and file
name instead of using the
-l
string or
-l
dir options for the linker to resolve global symbols with
shared libraries.
- You can indicate that
ld
should not search its list of
standard directories at all by specifying the
-l
option. When you do so, you must specify all libraries on the
f90
command line in some form, including the directory for
f90
standard libraries.
To specify all libraries, you might use the
-l
option in combination with the
-l
dir option on the same
f90
command line.
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:
- The
-call_shared
option is the default. It indicates that
.so
files are searched before
.a
files. As
ld
attempts to resolve external symbols, it looks at the shared library
before the corresponding archive library. For instance,
/usr/shlib/libc.so
is searched before
/usr/lib/libc.a
.
References to symbols found in
.so
libraries are dynamically loaded into memory at run time.
References to symbols found in
.a
libraries are loaded into the executable program file at link time.
- The
-non_shared
option indicates that only
.a
files are searched, so the object file created contains static
references to external routines. These static references are loaded
into the executable program at link time, not at run time. Corresponding
.so
files are not searched.
The following example requests that the
standard
f90
.a
files be searched instead of the corresponding
.so
files:
% f90 -non_shared main.f rest.o
|
- The
-shared
option requests
the creation of an executable program to be included in a shared
library.
- If you specify the
-c
option to inhibit linking, an object file (
.o
file) is created that can subsequently be processed by
ld
to create a shared library.
- If you omit the
-c
option, the
f90
command creates a shared library (
.so
file).
In either case, use the
-o
option to name the resulting object file or shared library with the
correct file name and suffix.
For more information about creating a
shared library using either the
f90
command or the
ld
command, see Section 2.6.
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 must specify the
-shared
option to create the
.so
file.
- You can specify the
-o output
option to name the output file.
- If you omit the
-c
option, you will create
a shared library (
.so
file) directly from the
f90
command line in a single step.
If you also omit the
-o output
option, the file name of the first Fortran file on the command line is
used to create the file name of the
.so
file. You can specify additional options associated with shared library
creation.
- If you specify the
-c
option, you will create an object file (
.o
file) that you can name with the
-o
option. To create a shared library, process the
.o
file with
ld
, specifying certain options associated with shared library creation.
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:
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
|
- The
-shared
option is required to create a shared library.
- The
-no_archive
option indicates that
ld
should not search archive libraries to resolve external names (only
shared libraries).
- The name of the object file is
octagon.o
. You can specify multiple object (
.o
) files.
- The
-lufor
and subsequent options are
the standard list of libraries that the
f90
command would have otherwise passed to
ld
. When you create a shared library, all symbols must be resolved. For
more information about the standard list of libraries used by
DIGITAL Fortran 90, see Section 2.5.
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:
- Certain
ld
options may not be available from the
f90
command line. If you need to use those options, use the two-command
method (specify
f90
-c
and subsequently use
ld
). Such options include
-check_registry
and
-update_registry
(see ld(1)).
- If you use a single
f90
command with
-shared
and omit
-c
, you do not need to specify the standard list of
f90
libraries by using the
-lstring
option.
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:
- Shared libraries must not be linked with archive libraries.
When creating a shared library, you can only depend on other shared
libraries for resolving external references. If you need to reference a
routine that currently resides in an archive library, either put that
routine in a separate shared library or include it in the shared
library being created. You can specify multiple object (
.o
) files when creating a shared library.
To put a routine in a
separate shared library, obtain the source or object file for that
routine, recompile if necessary, and create a separate shared library.
You can specify an object file when recompiling with the
f90
command or when creating the shared library with the
ld
command.
To include a routine in the shared library being created,
put the routine (source or object file) with other source files that
make up the shared library and recompile if necessary.
Then create
the shared library, making sure that you specify the file containing
that routine either during recompilation or when creating the shared
library. You can specify an object file when recompiling with the
f90
command or when creating the shared library with the
ld
command.
- When creating shared libraries, all symbols must be defined
(resolved).
Because all symbols must be defined to
ld
when you create a shared library, you must specify the shared libraries
on the
ld
command line, including all standard DIGITAL Fortran 90 libraries. The list
of standard DIGITAL Fortran 90 libraries might be specified by using the
-lstring
option, as in the previous example in this section.
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:
- To install a private shared library (when you are testing,
for example), set the environment variable LD_LIBRARY_PATH, as
described in loader(5).
- To install a system-wide shared library, place the shared
library file in one of the standard directory paths used by
ld
(see loader(5) or Section 3.48).
For complete information on installing shared libraries, see the
DIGITAL UNIX Programmer's Guide.