public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* static vs. dynamic libraries
@ 2004-05-11 16:05 Conklin, Larry
  2004-05-11 16:18 ` Eljay Love-Jensen
  0 siblings, 1 reply; 2+ messages in thread
From: Conklin, Larry @ 2004-05-11 16:05 UTC (permalink / raw)
  To: gcc-help

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: static vs. dynamic libraries
  2004-05-11 16:05 static vs. dynamic libraries Conklin, Larry
@ 2004-05-11 16:18 ` Eljay Love-Jensen
  0 siblings, 0 replies; 2+ messages in thread
From: Eljay Love-Jensen @ 2004-05-11 16:18 UTC (permalink / raw)
  To: Conklin, Larry, gcc-help

Hi Larry,

This is a VERY platform (OS + GCC version) sensitive way to solve the 
problem, as a target using GNU Make (I presume you know where the tabs go):

myfoo : foo.cpp
$(CXX) -o $@ $^ \
-nodefaultlibs \
-Wl,-Bstatic \
$(shell $(CXX) -print-file-name=libstdc++.a) \
$(shell $(CXX) -print-file-name=libgcc.a) \
$(shell $(CXX) -print-file-name=libgcc_eh.a) \
-Wl,-Bdynamic \
-lpthread -lc -lm -ldl

CAVEAT:  Use with caution!  This may work on, say, Solaris, and be 
completely wrong for, say, AIX or Linux.  And the libraries may be correct 
for GCC 3.2, and wrong for GCC 3.3.  Your mileage may vary.

HTH,
--Eljay

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-05-11 16:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-11 16:05 static vs. dynamic libraries Conklin, Larry
2004-05-11 16:18 ` Eljay Love-Jensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).