Choosing Archive or Shared Libraries with
If both an archive and shared version of a particular library reside in the same directory, ld links with the shared version. Occasionally, you might want to override this behavior.
As an example, suppose you write an application that runs on a system on which shared libraries may not be present. Since the program cannot run without the shared library, it would be best to link with the archive library resulting in executable code that contains the required library routines. See also“Caution When Mixing Shared and Archive Libraries” (page 118)
Option Settings to
The
The different option settings are:
Select archive libraries. If the archive library does not exist, ld generates an | ||
| error message and does not generate the output file. | |
Select shared libraries. If the shared library does not exist, ld | ||
|
| generates an error message and does not generate the output file. |
This is the same as | ||
Select the archive library if it exists; otherwise, select the shared library. | ||
|
| If the library is not found in either version, ld generates an error |
|
| message and does not generate the output file. |
Select the shared library if it exists; otherwise, select the archive library. | ||
|
| If the library is not found in either version, ld generates an error |
|
| message and does not generate the output file. |
The
CAUTION: You must avoid mixing shared libraries and archive libraries in the same application. For more information, see “Caution When Mixing Shared and Archive Libraries” (page 118)
Example Using
The following command links with the archive versions of libcurses, libm, and libc:
$ ld /opt/langtools/lib/hpux32/crt0.o prog.o
Linking Shared Libraries with
Use the
This option is on by default.
For example:
$ ld main.o
is the same as:
$ ld main.o
If you specified an archive library, the linker links it in, but the resulting executable is still a
36 Determining How to Link Programs or Libraries (Linker Tasks)