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.
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.
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...> -K -r file.f # xlf95 passes all these options to ld
The compiler passes unrecognized options, except -q options, on to the ld command.
XL Fortran allows your programs to take advantage of the operating system facilities for dynamic linking:
Dynamically linked programs take up less disk space and less virtual memory if more than one program uses the routines in the shared libraries. During linking, they do not require any special precautions to avoid naming conflicts with library routines. They also allow you to upgrade the routines in the shared libraries without relinking.
Because this form of linking is the default, you need no additional options to turn it on.
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:
| XLF-Provided Function Name | Common Block or Subprogram Name You Cannot Use |
|---|---|
| mclock | times |
| rand | irand |
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.
