|
Static Linking X11R6.3 |
![]() Wiscinfo |
![]() CS Home |
![]() 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.
% cc -o foo foo.o bar.o -L/s/X11R6.3-1/lib -R/s/X11R6.3-1/lib \ -B static -lX11 -lXext -B dynamic -lXt -lSM -lsocket -lnsl
% cc -o foo foo.o bar.o -L/s/X11R6.3-1/lib -R/s/X11R6.3-1/lib \ -non-shared -lX11 -lXext -lc_r -lXt -lSM -lsocket -lnsl
% gcc -o foo foo.o bar.o -L/s/X11R6.3-1/lib -R/s/X11R6.3-1/lib \ -static -lX11 -lXext -dynamic -lXt -lSM -lsocket -lnsl
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 */