Contents

 

About This Document...................................................................................

13

Intended Audience..................................................................................................................

13

Document conventions and symbols..........................................................................................

13

Related Information.................................................................................................................

13

HP Encourages Your Comments................................................................................................

14

Document Organization..........................................................................................................

14

1 Compiling and Linking Programs on HP-UX..................................................

16

Compiling Programs on HP-UX: An Example..............................................................................

16

Overview..........................................................................................................................

16

Looking Inside a Compiler...................................................................................................

18

What is an Object File?.................................................................................................

18

Local Definitions.......................................................................................................

19

Global Definitions....................................................................................................

19

External References...................................................................................................

19

Compiler-Linker Interaction..................................................................................................

19

Linking Programs on HP-UX......................................................................................................

21

The crt0.o Startup File........................................................................................................

21

The Program's Entry Point...............................................................................................

22

The a.out File....................................................................................................................

22

Magic Numbers (PA-RISC ONLY).........................................................................................

22

File Permissions..................................................................................................................

23

Linking with Libraries...............................................................................................................

23

Library Naming Conventions...............................................................................................

24

Default Libraries.................................................................................................................

24

The Default Library Search Path.......................................................................................

24

Link Order........................................................................................................................

24

Running the Program...............................................................................................................

25

Loading Programs: exec......................................................................................................

25

Binding Routines to a Program.............................................................................................

25

Deferred Binding is the Default............................................................................................

25

Linker Thread-Safe Features......................................................................................................

26

Shared library loading and unloading in multi-threaded applications.......................................

26

2 Determining How to Link Programs or Libraries (Linker Tasks)..........................

27

Using the Compiler to Link.......................................................................................................

28

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

28

Example Using -Wl,-L....................................................................................................

28

Getting Verbose Output with -v............................................................................................

29

Passing Linker Options from the Compiler Command with -Wl..................................................

29

Example Using -Wl........................................................................................................

29

Renaming the Output File with -o..........................................................................................

29

Specifying Libraries with -l...................................................................................................

29

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

30

Suppressing the Link-Edit Phase with -c..................................................................................

30

Using Linker Commands..........................................................................................................

30

Linking with the crt0.o Startup File........................................................................................

30

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

30

Overriding the Default Linker Search Path with LPATH.........................................................

30

Augmenting the Default Linker Search Path with -L..............................................................

31

Augmenting the Default Linker Search Path with +origin......................................................

31

Using $ORIGIN.................................................................................................................

31

Contents 3