User's Manual
Getting Verbose Output with -v
The -v option makes a compiler display the verbose information. This is useful for viewing how
the compiler calls ld. For example, using the -v option with the C compiler shows that it
automatically links with libc.
$ cc -v himom.c
/opt/ansic/lbin/ecom -ia64abi all -architecture 32 -ext on -lang c \
-exception off -sysdir /usr/include -inline_power 1 -link_type dynamic \
-fpeval float -tls_dyn on -target_os 11.23 -- sys_include /usr/include \
-D__hpux -D__unix -D__ia64=1 -D_BIG_ENDIAN=1 -D_ILP32 -D__HP_cc=60200 \
-D__STDC_EXT__ -D_HPUX_SOURCE -D_INCLUDE_LONGLONG -D_INLINE_ASM \
-D_BIND_LIBCALLS -D_Math_errhandling=MATH_ERREXCEPT -D_FLT_EVAL_METHOD=0 \
-ucode hdriver=optlevel%1% -plusolistoption -O106const! -plusolistoption \
-O113moderate! -plusooption -Oq01,al,ag,cn,sz,ic,vo,Mf,Po,es,rs,Rf,Pr,sp,\
in,cl,om,vc,pi,fa,pe,rr,pa,pv,nf,cp,1x,Pg,ug,1u,lb,uj,dn,sg,pt,kt,em,np,\
ar,rp,dl,fs,bp,wp,pc,mp,lr,cx,cr,pi,so,Rc,fa,ft,fe,ap,st,lc,Bl,sr,ib,pl,\
sd,ll,rl,dl,Lt,ol,fl,lm,ts,rd,dp,If! himom.c
LPATH=/usr/lib/hpux32:/opt/langtools/lib/hpux32
/usr/ccs/bin/ld -o a.out -u__exit -umain himom.o -lc
removing /var/tmp/AAAa17931
removing himom.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 instructing 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 instructing the linker to use an archive version of libm is:
$ $ ld /opt/langtools/lib/crt0.o mathprog.o -a archive -lm
-a default -lc
Renaming the Output File with -o
The -o name option causes ld to name the output file name instead of a.out. For example, to
compile a C program prog.c and name the resulting file sum_num:
$ cc -Aa -o sum_num prog.c //Compile using -o option.
$ sum_num //Run the program.
Enter a number to sum: 5
The sum of 1 to 5: 15
Specifying Libraries with -l
Sometimes programs call routines not contained in the default libraries. In such cases you must
explicitly specify the necessary libraries on the compile line with the -l option. The compilers pass
-l options directly to the linker before any default libraries, such as libc.
For example, if a C program calls library routines in the curses library (libcurses), you must
specify -lcurses on the cc command line: .
Using the Compiler to Link 29