static vs. dynamic libraries

Conklin, Larry Larry.Conklin@wiltel.com
Tue May 11 16:05:00 GMT 2004


We are currently writing an application that will be deployed on Solaris 8, Solaris 9 and RedHat 7.2. Past deployments we have had problems with the shared libraries so this release we want to use the static linking so that we don't have to worry about deploying the shared libraries. We recently upgraded our gcc compiler to 3.3.2.

I have read many misleading things about using and mixing static and dynamic libraries on the web. It is my understanding that we really only want to statically link in stdc++ and libgcc. Currently my make file says it can't find the static version of pthread. My problem is that I can't figured out how to statically link in stdc++ and gcc and keep libraries like pthread as dynamic. Can anyone help???

include ${XERCESCROOT}/version.incl
include ${XERCESCROOT}/samples/Makefile.incl

ifeq (${OSTYPE}, linux-gnu)
   myCC = /usr/bin/g++
   DLIBS = -lresolv -lnsl -ldl -lrt -lm -lpthread
else
   myCC = /usr/local/bin/g++
   DLIBS = -static-libgcc -lresolv -lnsl -ldl -lrt -lm -lpthread.so -lsocket -lgen
endif

COMMON_LIB=${SLM_COMMON}/libSLMCommon.a
myXerces=/home/slm/xerces/obj/SOLARIS/xerces.a
COMPILE_OPTIONS = -c -g -D_REENTRANT
myINCLUDES =  -I${SLM_COMMON} -I.

OBJS = main.o udpSocket.o udpWorker.o application.o udpPitcherConfiguration.o

APP_NAME=UDP_Pitcher

default: ${APP_NAME}

udpSocket.o : udpSocket.cpp
	${myCC} ${COMPILE_OPTIONS} ${INCLUDES} ${myINCLUDES} ${CMP} udpSocket.cpp

udpPitcherConfiguration.o : udpPitcherConfiguration.cpp
	${myCC} ${COMPILE_OPTIONS} ${INCLUDES} ${myINCLUDES} ${CMP} udpPitcherConfiguration.cpp

udpWorker.o : udpWorker.cpp
	${myCC} ${COMPILE_OPTIONS} ${INCLUDES} ${myINCLUDES} ${CMP} udpWorker.cpp

main.o : main.cpp
	${myCC} ${COMPILE_OPTIONS} ${INCLUDES} ${myINCLUDES} ${CMP} main.cpp

application.o : application.cpp
	${myCC} ${COMPILE_OPTIONS} ${INCLUDES} ${myINCLUDES} ${CMP} application.cpp

${APP_NAME} :	${OBJS}  
	${myCC} -static ${PLATFORM_LIB_LINK_OPTIONS} ${OBJS}  ${LIBRARY_SEARCH_PATHS} ${COMMON_LIB} ${myXerces} ${EXTRA_LINK_OPTIONS} ${DLIBS} -o $@

clean:
	\rm -f ${OBJS} core ${APP_NAME}

Larry Conklin
Office: 918.547.7131
SLM support pager 918.764.2421
SLM email support pager 9187642421@airmessage.net




More information about the Gcc-help mailing list