Compaq Fortran
User Manual for
Tru64 UNIX and Linux Alpha Systems


Previous Contents Index

2.3.2 Compiler Diagnostic Messages and Error Conditions

The Compaq Fortran compiler identifies syntax errors and violations of language rules in the source program. If the compiler finds any such errors, it writes messages to the stderr output file and any listing file. If you enter the f90 command interactively, the messages are displayed on your terminal.

Compiler messages have the following format:


 f90: severity: filename, line n, message-text 
 [text-in-error] 
 --------^ 

The pointer ( ---^ ) indicates the exact place on the source program line where the error was found. For example, the following error message shows the format and message text in a listing file when an END DO statement was omitted:


f90: Severe: echar.f, line 7: Unclosed DO loop or IF block 
        DO I=1,5 
--------^ 

Diagnostic messages usually provide enough information for you to determine the cause of an error and correct it.

2.3.3 Linker Diagnostic Messages and Error Conditions

If the linker detects any errors while linking object files, it displays messages about their cause and severity. If any errors occur, the linker does not produce an executable program file.

Linker messages are descriptive, and you do not normally need additional information to determine the specific error. On Tru64 UNIX systems, the general format for ld messages follows:


ld: 
message-text

On Linux systems, the general format for ld messages follows:


message-text

The message-text may be on multiple lines and is sometimes accompanied by an f90 or fort error.

Some common errors that occur during linking resemble the following:

If an error occurs when you link files, you may be able to correct it by retyping the command string and specifying the correct routines or libraries ( -l string option, -L dir option), or by specifying the object library or object files on the command line.

For More Information:

2.4 Compilation Control: Statements and Directives

In addition to option arguments on the f90 command, several statements used in the body of a Fortran program and cpp directives also influence the compilation process.

For More Information:

2.5 Specifying Object Libraries for Linking

Within a Fortran 95/90 program, references to procedures defined outside your program unit need to be declared as external symbols by using the EXTERNAL statement. (In order for BLOCK DATA statement symbols to be resolved by the linker, the BLOCK DATA symbol must be declared EXTERNAL and not have its data type declared in the source program unit.)

During compilation of multiple source files that will be placed into a single object or executable file, the Compaq Fortran compiler resolves those symbols referenced in one compilation unit and defined in another before linking occurs.

Upon successful compilation of a Compaq Fortran program, the f90 command specifies certain libraries for ld to search for unresolved external symbols in the object file (or files), such as calls to routines in libraries.

You can also specify additional object libraries on the f90 command line by using certain options or by providing the file name of the library. These object libraries are also searched by ld for unresolved external references.

When f90 specifies certain libraries to ld , it provides a standard list of f90 library file names to ld . The ld linker tries to locate each of these library file names in a standard list of library directories; ld attempts to locate each object library file name first in one directory, then in the second, and then in the third directory on its search list of directories.

To display a list of the compilers invoked, files processed, and libraries accessed during linking, specify the -v option on the f90 command line.

In addition to an object file created by the compiler, any linker options and object files specified on the f90 command are also passed to the ld linker. The linker loads object files according to the order in which they are specified on the command line. Because of this, you must specify object libraries after all source and object files on the f90 command line.

For more details on the interaction of the f90 command with other components, see Section 2.2.1.

To help you identify undefined references to routines or other symbols in an object file, consider using the nm command. For instance, the following nm command filtered by the grep command lists all undefined (U) symbols:


% nm -o ex.o | grep U

If the symbol is undefined, a "U" appears in the column before the symbol name. Any symbols with a U in their names are also displayed by this use of grep .

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

Note that the -no_archive option is available only on Tru64 UNIX systems.

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 (TU*X ONLY), which preassign 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 Compaq Fortran, 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 Compaq Tru64 UNIX Programmer's Guide.


Previous Next Contents Index