University of Wisconsin Madison

Static Linking X11R6.3

Wiscinfo
Wiscinfo
CS Home
CS Home
CSL
CSL

The X11R6.3 environment in the CS department includes a facility for building statically linked applications. The advantage of doing this is that applications built in this way do not depend on the presence of dynamic X libraries to run. The down side is that statically linked applications are generally much larger than dynamically linked applications.

All the standard X libraries have been built as both archives and dynamic libraries. There is also imake support for both vendor compilers and gcc.


Linking by hand with the archives

The following examples all show a hypothetical application foo, linked with static versions of the X11 and Xext libraries and dynamic versions of Xt and SM (the system libraries c, socket, nsl, etc. are always linked dynamically. Also, if you link all the X libraries statically, you don't need to include the -R path).

Building with an Imakefile

The macros used below are not part of the standard X11R6.3 distribution. They are local hacks only, and will be no-ops at any other site. If you want the additional Imakefile code to define the $(LDSTATICFLAGS) and $(LDDYNAMICFLAGS) macros, check out the site.def code that defines them.

When defining LOCAL_LIBRARIES, surround the libraries you want linked dynamically with the macros $(LDSTATICFLAGS) and $(LDDYNAMICFLAGS), as in:

LOCAL_LIBRARIES = $(LDSTATICFLAGS) $(XMULIB) $(XTOOLLIB) $(XLIB) \
$(XAUTHLIB) $(XDMCPLIB) $(RPCLIB) $(UWLIBS) $(LDDYNAMICFLAGS) $(DLLIBRARY)
Then reference $(LOCAL_LIBRARIES) in the ComplexProgramTarget_1 as usual (the reference is implied in NormalProgramTarget. imake will generate the correct linker flags based on your machine architecture and compiler.

An example use of this method can ba found in /afs/cs.wisc.edu/s/X11R6.3-1/src/xc/programs/xdm/Imakefile, (our local xdm Imakefile), which builds a statically linked xdm for our department.


site.def code

This is the scrap from our site.def file that defines the Imakefile macros.

# if HasGcc2
#  define StaticLinkFlags -static
#  define DynamicLinkFlags  -dynamic
# else /* Using vendor compilers - gross!) */
#  if defined (SVR4Architecture) && defined (SunArchitecture)
#   define StaticLinkFlags -B static
#   define DynamicLinkFlags  -B dynamic
#  endif /* Sun SVR4 */
#  if defined (AlphaArchitecture)
#   define StaticLinkFlags -non_shared
#   define DynamicLinkFlags -lc_r
#  endif /* Alpha */
# endif /* HasGcc2 else */


Last modified: Wed Mar 12 13:58:01 CST 1997
thomas@cs.wisc.edu