$ cc -Aa -v cursesprog.c -lcurses

...

/usr/ccs/bin/ld /opt/langtools/lib/crt0.o cursesprog.o -lcurses \ -u main -lc

cc: informational note 413: Entering Link editor.

Linking with the crt0.o Startup File in 32-bit mode (PA-RISC)

Notice also, in the above example, that the compiler linked cursesprog.o with the file /opt/langtools/lib/crt0.o. This file contains object code that performs tasks which must be executed when a program starts running - for example, retrieving any arguments specified on the command line when the program is invoked. For details on this file, see “The crt0.o Startup File” (page 21)

Suppressing the Link-Edit Phase with -c

The -ccompiler option suppresses the link-edit phase. That is, the compiler generates only the .o files and not the a.out file. This is useful when compiling source files that contain only subprograms and data. These may be linked later with other object files, or placed in an archive or shared library. The resulting object files can then be specified on the compiler command line, just like source files. For example:

$ f90

-c func.f

//Produce .o for

func.f.

$ ls func.o

 

 

 

func.o

 

 

 

 

$

f90

main.f func.o

//Compile main.f

with

func.o

$

a.out

//Run it to verify it

worked.

Using Linker Commands

This section describes linker commands for the 32-bit and 64-bit linker

NOTE: Unless otherwise noted, all examples show 32-bit behavior.

Linking with the crt0.o Startup File

In default mode, you need not include crt0.o on the link line. However, you must include crt0.o on the link line for all fully archive links (ld -noshared) and in compatibility mode (+compat). You need not include the crt0.o startup file on the ld command line for shared bound links. The dynamic loader does some of the startup duties previously done by crt0.o.

See “The crt0.o Startup File” (page 21), and crt0(3) manpage for more information.

Changing the Default Library Search Path with -L, LPATH, and $ORIGIN

You can change or override the default linker search path by using the LPATH environment variable, the -Llinker option, or the +origin linker option.

Overriding the Default Linker Search Path with LPATH

The LPATH environment variable allows you to specify which directories ld should search. If LPATH is not set, ld searches the default directory /usr/lib. If LPATH is set, ld searches only the directories specified in LPATH; the default directories are not searched unless they are specified in LPATH.

If set, LPATH must contain a list of colon-separated directory path names that ld must search. For example, to include /usr/local/lib in the search path after the default directories, set LPATH as follows:

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