Linking XL Fortran programs

By default, you do not need to do anything special to link an XL Fortran program. The compiler invocation commands automatically call the linker to produce an executable output file. For example, running the following command:

xlf95 file1.f file2.o file3.f

compiles and produces object files file1.o and file3.o, then all object files are submitted to the linker to produce one executable.

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 (file1.o)
xlf95 -c file2.f file3.f       # Or multiple object files (file1.o, file3.o)
xlf95 file1.o file2.o file3.o  # Link object files 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.

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 -Wl,<options...> file.f # xlf95 passes all these options to ld

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

Dynamic and Static Linking

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

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.