24.05.2014 Views

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

v<br />

Static linking means that the code <strong>for</strong> all routines called by your program<br />

becomes part of the executable file.<br />

Statically linked programs can be moved to and run on systems without the <strong>XL</strong><br />

<strong>Fortran</strong> libraries. They may per<strong>for</strong>m better than dynamically linked programs if<br />

they make many calls to library routines or call many small routines. They do<br />

require some precautions in choosing names <strong>for</strong> data objects and routines in the<br />

program if you want to avoid naming conflicts with library routines (as<br />

explained in “Avoiding Naming Conflicts during Linking”). They also may not<br />

work if you compile them on one level of the operating system and run them on<br />

a different level of the operating system.<br />

You can use -b linker options on the compiler command line to create statically<br />

linked object files:<br />

xlf95 -bnso -bI:/usr/lib/syscalls.exp file1.f file2.f<br />

You must also specify -bI:/usr/lib/threads.exp when you are statically linking<br />

with the xlf_r, xlf_r7, xlf90_r, xlf90_r7, xlf95_r, or xlf95_r7 command.<br />

If you are using Asynchronous I/O, you must also specify -bI:/usr/lib/aio.exp.<br />

The -bnso option places the library procedures that your program references into<br />

the program’s object file. Files with a suffix of .exp specify the names of system<br />

routines that must be imported to your program from the system.<br />

An alternative that requires less disk space is to link any <strong>XL</strong> <strong>Fortran</strong> libraries<br />

statically but to leave references to other system libraries dynamic. This example<br />

statically links just the <strong>XL</strong> <strong>Fortran</strong> libraries:<br />

# Build a temporary object from the <strong>Fortran</strong> library:<br />

ld -r -o libtmp.o -bnso -lxlf90<br />

# Build the application with this object on the command line:<br />

xlf95 -o appl appl1.o appl2.o libtmp.o<br />

Avoiding Naming Conflicts during Linking<br />

If you define an external subroutine, external function, or common block with the<br />

same name as a run-time subprogram, your definition of that name may be used<br />

in its place, or it may cause a link-edit error.<br />

Try the following general solution to help avoid these kinds of naming conflicts:<br />

v<br />

Compile all files with the -qextname option. It adds an underscore to the end of<br />

the name of each global entity, making it distinct from any names in the system<br />

libraries.<br />

v<br />

v<br />

Note: When you use this option, you do not need to use the final underscore in<br />

the names of Service and Utility Subprograms, such as dtime_ and flush_.<br />

Link your programs dynamically, which is the default. Many naming conflicts<br />

only apply to statically linked programs.<br />

Order the names of libraries and object files on the command line so that the<br />

one that should take precedence comes first. For example, to make names in<br />

libxlf90.a take precedence over duplicate names in an object file, specify -lxlf90<br />

first on the command line.<br />

If you do not use the -qextname option, you must take the following extra<br />

precautions to avoid conflicts with the names of the external symbols in the <strong>XL</strong><br />

<strong>Fortran</strong> and system libraries:<br />

v Do not name a subroutine or function main, because <strong>XL</strong> <strong>Fortran</strong> defines an entry<br />

point main to start your program.<br />

v Do not use any global names that begin with an underscore. In particular, the <strong>XL</strong><br />

<strong>Fortran</strong> libraries reserve all names that begin with _xl.<br />

Editing, Compiling, Linking, and Running <strong>XL</strong> <strong>Fortran</strong> Programs 47

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!