A PA-RISC processor name—for example, PA7100or PA8000.

portable—code that is compatible across all models. Use +DAportableonly if you want to ensure that your program will run on different models.

Use the uname -mcommand to learn the model of your machine, as follows:

$ uname

-m 9000/879

Alternatively, you can use the grep command to look up the model number in the file /opt/ langtools/lib/sched.modelsand find its architecture type, as follows:

$ grep 879 /opt/langtools/lib/sched.models

879

2.0

PA8000

You can also use the +DSmodeloption to specify an architecture-specific instruction scheduler, where model has the same meaning as it does for the +DAoption. Like the +DAoption, the +DSoption is unnecessary if the program will run on the same machine as you use to compile it. Also, if you compile with +DAmodel, the compiler will select the scheduling algorithm based on the same architecture—unless you use the +DSoption to specify a different architecture.

NOTE: Code generated for PA1.1 systems will execute on PA2.0 systems, but the reverse is not

true: the loader will not allow PA2.0 code to run on a PA1.1 system.

Creating shared libraries

As mentioned in “Linking to shared libraries” (page 53), many of the HP-UX as well as HP Fortran libraries are available in shared as well as archive versions. Linking with shared libraries can make the executable program smaller and can ensure that it always has the most current version of the library.

You can make shared versions of your own libraries, using the +piccommand-line option and the -blinker option. The following sections describe how to use these options and show an example of how to create a shared library.

Compiling with +pic

The +picoption causes the compiler to generate Position- Independent Code (PIC) for use in a shared library. PIC contains no absolute addresses and can therefore be placed anywhere in a process’s address space without addresses having to be relocated. This characteristic of PIC makes it shareable by multiple processes.

The syntax of the +pic option is:

+pic={shortlongno}

Although compiling with either +pic=short or +pic=longwill generate PIC, in general you should use the +pic=shortoption. If the linker issues an error message saying that the number of referenced symbols in the shared library exceeds its limit, recompile with +pic=long, which will cause the compiler to allocate space for a longer symbol table.

The +pic=no is the default, which causes the compiler to generate absolute code, such as you would want for executable programs.

The following command line creates three object files—x.o, y.o, and z.o; the code in each file will be PIC:

$ f90 -c +pic=short x.f90 y.f90 z.f90

For more information about the +picoption, see the HP Fortran Programmer’s Reference.

Special-purpose compilations

59

Page 59
Image 59
HP UX Fortran Software manual Creating shared libraries, Compiling with +pic