54 Chapter 3
Linker Tasks
Using the Compiler to Link
The LPATH environment variable provides another way to override the
default search path. For details, see “Changing the Default Library
Search Path with -L and LPATH”.
Getting Verbose Output with -v
The -v option makes a compiler display verbose information. This is
useful for seeing how the compiler calls ld. For example, using the -v
option with the Pascal compiler shows that it automatically links with
libcl, libm, and libc.
$ pc -v prog.p
/opt/pascal/lbin/pascomp prog.p prog.o -O0
LPATH = /usr/lib/pa1.1:/usr/lib:/opt/langtools/lib
/usr/ccs/bin/ld /opt/langtools/lib/crt0.o -z prog.o -lcl -lm -lc
unlink prog.o
Passing Linker Options from the Compiler
Command with -Wl
The -Wl option passes options and arguments to ld directly, without the
compiler interpreting the options. Its syntax is:
-Wl,arg1 [,arg2]…
where each argn is an option or argument passed to the linker. For
example, to make ld use the archive version of a library instead of the
shared, you must specify -a archive on the ld command line before
the library.
Example Using -Wl
The command for telling the linker to use an archive version of libm
from the C command line is:
$ cc -Aa mathprog.c -Wl,-a,archive,-lm,-a,default
The command for telling the linker to use an archive version of libm is:
$ ld /opt/langtools/lib/crt0.o mathprog.o -a archive -lm \
-a default -lc