I have problems linking my application statically.

I have problems linking my application statically.



In Solaris 2.x static linking is not supported for any of the
system libraries. All the functions that use /etc/nsswitch.conf
(getXXXbyYYY, getpwXXX, etc) require the dynamic linker to
load the code to load these functions. It is not possible
to write configurable/extensible functions in such a way that
dynamic linking is not required. E.g., you can add your own
nsswitch.conf backend which would not be known to programs
statically linked to only the standard backend code.


Programs that link statically against any of the OS libraries
may not run in the next release and are not ABI compliant.


Programs that link statically don't get some dynamic performance
enhancements found in the shared libraries: using hardware
multiply/divide on systems that support it; using fast mem*()
operations on UltraSPARC etc. And you won't pick up performance
enhancements in next releases: e.g., Solaris 2.5 comes with
a 4x faster fread/fwrite and the "Name Server Cache Daemon".


If you don't care about ABI compliance, i.e., you won't
ship your program as a product and don't care that you may
need to recompile after an OS upgrade, here are some of your
options:


Link statically against all but libdl:



cc -Bstatic .... -Bdynamic -ldl -Bstatic


Link against dl* stubs (gethostbyXXX, getpwXXX etc won't work any
longer):



char *dlopen() { return 0;}
int dlclose() { return 0;}
char *dlsym() { return 0;}
char *dlerror() { return "dynamic linking not loaded";}


If you don't want any dependencies on /usr, link against the dynamic
libs in /etc/lib:



cc -Bstatic ... -Bdynamic -R/etc/lib -Wl,-I/etc/lib/ld.so.1 -ldl
-Bstatic ....


If you still get undefined symbols, check with ldd for all your
libraries if they have any dynamic dependencies. E.g.,



% ldd /usr/lib/libsocket.so.1
libnsl.so.1 => /usr/lib/libnsl.so.1
libdl.so.1 => /usr/lib/libdl.so.1
libc.so.1 => /usr/lib/libc.so.1
libintl.so.1 => /usr/lib/libintl.so.1
libw.so.1 => /usr/lib/libw.so.1


tells you that if you want to link libsocket statically,
you need to link with -lnsl -ldl -lc -lintl and -lw as well.


There is no way to statically link 64 bit executables; no 64 bit
archive libraries are shipped with Solaris.


With Solaris 10, no archive libraries are being shipped and static
linking has gone the way of the dinosaur; for system libraries,
that is.





Home
FAQ