Linking Archived Libraries with
Use the
NOTE: You cannot link in shared libraries if you specify this option.
In the following example, the linker only looks for:
/usr/lib/hpux32/libfoo.a and /user/lib/hpux32/libc.a:
$ ld /usr/ccs/hpux32/crt0.o main.o
If you specify a shared library libbar.so with this option, the linker displays the error message:
ld: The shared library "libbar.so" cannot be processed in a static link. Fatal error.
Exporting Symbols with +e
The +e option allows you to hide and export symbols. Exporting a symbol makes the symbol a global definition, which can be accessed by other object modules or libraries. The +e option exports the symbol and hides from export all other global symbols not specified with +e. In essence,
The syntax of the +e option is:
+e symbol
Example Using +e
Suppose you want to build a shared library from an object file that contains the following symbol definitions as displayed by the nm command:
$ nm
0000000000 U $global$
1073741824 d $THIS_DATA$
1073741864 b $THIS_BSS$
0000000004 cS sem_val
0000000000 T check_sem_val
0000000036 T foo
0000000000 U printf
0000000088 T bar
0000000140 T sem
In this example, check_sem_val, foo, bar, and sem are all global definitions. To create a shared library where check_sem_val is a hidden, local definition, you could use either of the following commands:
$ ld | check_sem_val | sem.o | //One | ||
$ ld | +e | foo +e bar +e | sem sem.o | //Three +e options. |
In contrast, suppose you want to export only the check_sem_val symbol. Either of the following commands work:
$ ld | foo | sem sem.o | //Three | ||
$ ld | +e | check_sem_val | sem.o | //One +e option. |
When to use
How do you decide whether to use
Using Linker Commands 37