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.
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.
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.
XL Fortran allows your programs to take advantage of the operating system facilities for both dynamic and static 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 may perform better than statically linked programs if several programs use the same shared routines at the same time. 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.
Statically linked programs can be moved to and run on systems without the XL Fortran libraries. They may perform better than dynamically linked programs if they make many calls to library routines or call many small routines. They do require some precautions in choosing names for data objects and routines in the program if you want to avoid naming conflicts with library routines (as explained in Avoiding naming conflicts during linking). They also may not work if you compile them on one level of the operating system and run them on a different level of the operating system.
To link statically, add the --static option to the linker command. For example:
xlf95 -Wl,--static test.f
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.