XL Fortran for AIX 8.1

User's Guide


Linking XL Fortran Programs

By default, you do not need to do anything special to link an XL Fortran program. The linker is executed automatically to produce an executable output file:

xlf95 file1.f file2.o file3.f

After linking, follow the instructions in Running XL Fortran Programs to execute the program.

Compiling and Linking in Separate Steps

To produce object files that can be linked later, use the -c option.

xlf95 -c file1.f               # Produce one object file
xlf95 -c file2.f file3.f       # Or multiple object files
xlf95 file1.o file2.o file3.o  # Link with appropriate libraries

It is often best to execute the linker through the compiler invocation command, because it passes some extra ld options and library names to the linker automatically.

Linking 32-Bit SMP Object Files Using the ld Command

To use the ld command to link an SMP program, follow these guidelines:

On AIX Version 4.3 and higher, the default POSIX pthreads API is the 1003.1-1996 standard. If you had a program called mytest and you wanted to obtain access to the functions in the 1003.1-1996 standard POSIX pthreads API on AIX Version 4.3, you would link with the libpthreads.a library, using something similar to the following command:

ld -bh:4 -bpT:0x10000000 -bpD:0x20000000 /lib/crt0_r.o mytest.o -lxlf90_r
   -lxlf -lxlsmp -lm_r -lm -lc_r -lc -lpthreads -o mytest

The 1003.1-1996 standard is not fully compatible with Draft 7. If you have programs that require the Draft 7 interface, link your programs with the libpthreads_compat.a and libxlfpthrds_compat.a libraries (which provide compatibility support) followed by the libpthreads.a library. For example, if you have a program called mytest that was written to use the Draft 7 interface, on AIX Version 4.3, you would use something similar to the following command:

ld -bh:4 -bpT:0x10000000 -bpD:0x20000000 /lib/crt0_r.o mytest.o
   -lxlfpthrds_compat -lxlf90_r -lxlf -lxlsmp -lm_r -lm -lc_r -lc
   -lpthreads_compat -lpthreads -o mytest 

The configuration file /etc/xlf.cfg lists these default libraries and linker options. By doing a sample compilation with the -# option, you can see exactly how the compiler would run the linker.

See the AIX Commands Reference for a description of the linker options.

Linking 64-Bit SMP Object Files Using the ld Command

To use the ld command to link a 64-bit SMP program, follow these guidelines:

For example, to link the object files smpfile1.o and smpfile2.o, you could specify the following:

ld -bh:4 -bpT:0x10000000 -bpD:0x20000000 -b64 /lib/crt0_64.o -lxlf90 
   -lxlsmp -lm -lc smpfile1.o smpfile2.o

The configuration file /etc/xlf.cfg lists these default libraries and linker options. By doing a sample compilation with the -# option, you can see exactly how the compiler would run the linker.

See the AIX Commands Reference for a description of the linker options.

Linking 32-Bit Non-SMP Object Files Using the ld Command

To use the ld command to link non-SMP object files in a 32-bit environment, follow these guidelines:

For example, to link the object files file1.o and file2.o, you could specify the following:

  ld -bh:4 -bpT:0x10000000 -bpD:0x20000000 /lib/crt0.o -lxlf90 -lm -lc
     file1.o file2.o

The configuration file /etc/xlf.cfg lists these default libraries and linker options. By doing a sample compilation with the -# option, you can see exactly how the compiler would run the linker.

See the AIX Commands Reference for a description of the linker options.

Linking 64-Bit Non-SMP Object Files Using the ld Command

To use the ld command to link non-SMP object files in a 64-bit environment, follow these guidelines:

For example, to link the object files file1.o and file2.o, you could specify the following:

  ld -bh:4 -bpT:0x10000000 -bpD:0x20000000 -b64 /lib/crt0_64.o -lxlf90 -lm
     -lc file1.o file2.o

The configuration file /etc/xlf.cfg lists these default libraries and linker options. By doing a sample compilation with the -# option, you can see exactly how the compiler would run the linker.

See the AIX Commands Reference for a description of the linker options.

Passing Options to the ld Command

If you need to link with ld options that are not part of the XL Fortran default, you can include those options on the compiler command line:

   xlf95 -bhalt:2 -K -r file.f # xlf95 passes all these options to ld

The compiler passes unrecognized options, except -q options, on to the ld command.

Checking for Interface Errors at Link Time

If you specify the -qextchk compiler option, the linker may refuse to link object files containing mismatching procedure interfaces or common block definitions, allowing you to find these errors at link time, instead of trying to debug incorrect results.

If the linking problem can be isolated to a few names that do not resolve, perhaps because of uppercase letters in C names or trailing underscores added by the -qextname option, you can use the -brename linker option to change just those names:

  xlf95 -brename:Old_Link_Name,new_link_name fort_prog.o c_prog.o
Related Information:
See -qextchk Option, -U Option, and -qextname Option.

Linking New Objects with Existing Ones

If you have .o or other object files that you compiled with an earlier version of XL Fortran, you can link them with object files that you compile with XL Fortran Version 8, subject to the following notes. The main XL Fortran libraries are libxlf90.a and libxlf90_r.a, but calls to older entry points in libxlf.a are still possible; the calls are passed to the new entry points in the main libraries, which makes the resulting programs slower than if everything is recompiled.

Notes:

  1. You must explicitly specify the XL Fortran libxlf.a library as part of the link step, preferably by including the option -lxlf.

  2. For safety, always put -lxlf as the first option after the compiler command so that the library is linked before any user object files. Doing so ensures that the new I/O routines override any existing ones in statically linked object files.

  3. When you relink old object files, the I/O routines in the resulting program differ in some ways from the behavior of XL Fortran Version 2. To make the resulting program work as you expect, you may need to change some of the run-time settings in Setting Run-Time Options (particularly the namelist setting) or to recompile the source files with the -qxlf77 Option. Some changed I/O details cannot be switched to the old behavior at all.

  4. You cannot link files that you compiled with the XL Fortran Version 4 level of IPA with files that you compiled with the XL Fortran Version 6 level or later of IPA.

  5. You cannot link 64-bit objects compiled with XL Fortran version 7.1.0.1, or lower. The object format has changed on AIX Version 5.1.

  6. You cannot link pdf files that you created with -qpdf1 and Version 5.1.0 or earlier levels of XL Fortran with pdf files that you created with -qpdf1 and XL Fortran Version 7.1 or higher. However, you can link object files that you created with -qpdf2 and XL Fortran Version 7.1 or higher with object files that you created with -qpdf2 and earlier levels of XL Fortran.

Relinking an Existing Executable File

Because the linker accepts executable files as input, you can link an existing executable file with updated object files.You cannot, however, relink executable files that were previously linked using the -qipa option.

If you have a program consisting of several source files and only make localized changes to some of the source files, you do not necessarily have to compile each file again. Instead, you can include the executable file as the last input file when compiling the changed files:

  xlf95 -omansion front_door.f entry_hall.f parlor.f sitting_room.f \
    master_bath.f kitchen.f dining_room.f pantry.f utility_room.f
 
  vi kitchen.f # Fix problem in OVEN subroutine
 
  xlf95 -o newmansion kitchen.f mansion

Limiting the number of files to compile and link the second time reduces the compile time, disk activity, and memory use.

Note:
If this type of linking is done incorrectly, it can result in interface errors and other problems. Therefore, you should not try it unless you are experienced with AIX linking.

Dynamic and Static Linking

XL Fortran allows your programs to take advantage of the AIX operating system facilities for both dynamic and static linking:

Note:
When you run an XL Fortran program on a system without the XL Fortran message catalogs, run-time error messages (mostly for I/O problems) are not displayed correctly; the program prints the message number but not the associated text. To prevent this problem, copy the XL Fortran message catalogs from /usr/lpp/xlf/bin/default_msg to a directory that is part of the NLSPATH environment-variable setting on the execution system.

Avoiding Naming Conflicts during Linking

If you define an external subroutine, external function, or common block with the same name as a run-time subprogram, your definition of that name may be used in its place, or it may cause a link-edit error.

Try the following general solution to help avoid these kinds of naming conflicts:

If you do not use the -qextname option, you must take the following extra precautions to avoid conflicts with the names of the external symbols in the XL Fortran and system libraries:

Be careful not to use the names of subroutines or functions without defining the actual routines in your program. If the name conflicts with a name from one of the libraries, the program could use the wrong version of the routine and not produce any compile-time or link-time errors.

If different versions of a routine occur in more than one library or object file, be careful to use the specific version that you want. Specify the file with the correct version as the first file on the command line or in the configuration file. If the file is a library, specify the appropriate -l option first on the command line. This technique does not apply to references between routines that are in the same shared library or to routines that are explicitly imported from one shared library to another.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]