Resolve re-linking errors

To resolve linking errors, you need to step through the linking process performed by the linker. To do this, perform the following procedures:

  1. View the linking script
  2. Include the startup library
  3. Include the checkpoint library
  4. Force static linking

View the linking script

View the low-level linking script by running your linker in verbose mode.

This will display the libraries called by your linker. Use this information to help determine which files need to be replaced.

Refer to the man page supplied with your compiler to determine the verbose mode switch. The following table lists the verbose mode switch for some operating systems.


Operating System

Verbose Mode Switch

SUNOS/Solaris

-#

AIX

-v

IRIX

-show -non_shared

HP-UX

-v

OSF1

-v -non_shared


For example, running the Sparc C Compiler 3.0 with the verbose switch, -#, for my_job.o:

% cc -o -# my_job my_job.o
/usr/ccs/bin/ld /opt/SUNWspro/SC3.0/lib/crti.o /opt/SUNWspro/SC3.0/lib/crt1.o /opt/SUNWspro/SC3.0/lib/__fstd.o /opt/SUNWspro/SC3.0/lib/values-xt.o -o my_job my_job.o -Y P,/opt/SUNWspro/SC3.0/lib:/usr/ccs/lib:/usr/lib -Qy -lc /opt/SUNWspro/SC3.0/lib/crtn.o

Include the startup library

Add the startup library:

Replace the library that calls main() with ckp_crt0.o. To determine which library calls main(), run nm for all libraries listed in the low-level linking script. For example:
% nm /opt/SUNWspro/SC3.0/lib/crt1.o | grep -i main

Replace /opt/SUNWspro/SC3.0/lib/crt1.o with /usr/share/lsf/lib/ckpt_crt0.o:

/usr/ccs/bin/ld /opt/SUNWspro/SC3.0/lib/crti.o /usr/share/lsf/lib/ckpt_crt0.o /opt/SUNWspro/SC3.0/lib/__fstd.o /opt/SUNWspro/SC3.0/lib/values-xt.o -o my_job my_job.o -Y P,/opt/SUNWspro/SC3.0/lib:/usr/ccs/lib:/usr/lib -Qy -lc /opt/SUNWspro/SC3.0/lib/crtn.o

Include the checkpoint library

Add libckpt.a after language-specific libraries and before system-specific libraries. For example:
/usr/ccs/bin/ld /opt/SUNWspro/SC3.0/lib/crti.o /usr/share/lsf/lib/ckpt_crt0.o /opt/SUNWspro/SC3.0/lib/__fstd.o /opt/SUNWspro/SC3.0/lib/values-xt.o -o my_job my_job.o /usr/share/lsf/lib/libckpt.a -Y P,/opt/SUNWspro/SC3.0/lib:/usr/ccs/lib:/usr/lib -Qy -lc /opt/SUNWspro/SC3.0/lib/crtn.o

Force static linking

Force your application to link statically to as many libraries as possible.

Refer to the documentation supplied with your compiler for more information about static linking. For example, on Solaris the -Bstatic and -Bdynamic compiler switches are used to force modules to statically link wherever possible:

/usr/ccs/bin/ld ‑Bstatic /opt/SUNWspro/SC3.0/lib/crti.o /usr/share/lsf/lib/ckpt_crt0.o /opt/SUNWspro/SC3.0/lib/__fstd.o /opt/SUNWspro/SC3.0/lib/values-xt.o ‑o my_job my_job.o /usr/share/lsf/lib/libckpt.a ‑Y P,/opt/SUNWspro/SC3.0/lib:/usr/ccs/lib:/usr/lib ‑Qy ‑lc ‑Bdynamic ‑ldl ‑Bstatic /opt/SUNWspro/SC3.0/lib/crtn.o