“Specifying Libraries with -l and -l:” (page 45)

“Flagging Unsatisfied Symbols with +[no]allowunsats” (page 45)

“Stripping Symbol Table Information from the Output File with -s and -x” (page 46)

“Controlling Output from the Unwind Table with +strip unwind” (page 46)

“Using the IPF Linker with +compat or +std” (page 46)

“Linking in PA-64 Mode with +std” (page 48)

“Linking in PA-32 Mode with +compat” (page 48)

“Changing Mapfiles with -k and +nodefaultmap” (page 48)

“Selecting Verbose Output with +vtype” (page 48)

“Turning on the linkage table protection with +protect” (page 50)

“Allocating Storage for Uninitialized Data with +nobss” (page 50)

“Initializing Floating Point Environment with +FP ” (page 50)

“Allocating Storage for Hidden Common Symbols with +alloc_hidden_commons” (page 51)

“Turn Off Linker Warnings with -w” (page 52)

“Preserving Compiler Generated Relocation Sections with -emit_relocs” (page 52)

Using the Compiler to Link

In many cases, you use your compiler command to compile and link programs. Your compiler uses options that directly affect the linker.

Changing the Default Library Search Path with -Wl, -L

The -Llibpath option to ld augments the default search path; that is, it causes ld to search the specified libpath before the default places. The C compiler (cc), the C++ compiler (CC), the POSIX FORTRAN compiler (fort77), and the HP Fortran 90 compiler (f90) recognize the -L option and pass it directly to ld. However, the HP FORTRAN compiler (f77) and Pascal compiler (pc) do not recognize -L; it must be passed to ld with the -Wl option.

Example Using -Wl, -L

For example, to make the f77 compiler search /usr/local/lib to find a locally developed library named liblocal, use this command line:

$ f77 prog.f -Wl,-L,/usr/local/lib -llocal

(The f77 compiler searches /opt/fortran/lib and /usr/lib as default directories.)

To make the f90 compiler search /usr/local/lib to find a locally developed library named liblocal, use this command line:

$ f90 prog.f90 -L/usr/local/lib -llocal

(The f90 compiler searches /opt/fortran90/lib and /usr/lib as default directories.) For the C compiler, use this command line:

$ cc -Aa prog.c -L /usr/local/lib -llocal

The LPATH environment variable provides another way to override the default search path. For details, see “Changing the Default Library Search Path with -L, LPATH, and $ORIGIN” (page 30)

28 Determining How to Link Programs or Libraries (Linker Tasks)

Page 28
Image 28
HP UX Software Transition Kit (STK) Using the Compiler to Link, Changing the Default Library Search Path with -Wl, -L