Article View: gnu.g++.help
Article #198static constructors and libraries
From: Bradley D. Keister
Date: Wed, 19 Aug 1992 08:27
Date: Wed, 19 Aug 1992 08:27
212 lines
6337 bytes
6337 bytes
I've been told that my description of the problem of static
constructors and libraries on a SPARC was not specific enough.
Enclosed below is a shell archive which contains small test files
whose output is the value of pi. The executable "nolibtest" links two
.o files together without the use of the library, and "libtest" links
the test .o file with the library containing the static initializer.
Both methods SHOULD yield
pi test: 3.14159
My version of nolibtest on a SPARC yields the correct value, and my
version of libtest yields
pi test: 0.00000
Sun CC, DECstation CC and DECstation g++ give the correct value for
both methods.
Brad Keister
Department of Physics
Carnegie Mellon University
Pittsburgh, PA 15213
(412) 268-2772 (office)
(412) 681-0648 (FAX)
internet: keister@poincare.phys.cmu.edu
BITNET: keister%poincare.phys.cmu.edu@CARNEGIE
---------------------------------------------------
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive 1 (of 1)."
# Contents: MANIFEST Makefile README physmath.c physmath.h pmtest.c
# Wrapped by keister@poincare.phys.cmu.edu on Wed Aug 19 09:24:15 1992
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'MANIFEST' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'MANIFEST'\"
else
echo shar: Extracting \"'MANIFEST'\" \(300 characters\)
sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
X File Name Archive # Description
X-----------------------------------------------------------
X MANIFEST 1 This shipping list
X Makefile 1
X README 1
X physmath.c 1
X physmath.h 1
X pmtest.c 1
END_OF_FILE
if test 300 -ne `wc -c <'MANIFEST'`; then
echo shar: \"'MANIFEST'\" unpacked with wrong size!
fi
# end of 'MANIFEST'
fi
if test -f 'Makefile' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(491 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X
CCX= g++
OBJFILES= pmtest.o physmath.o
INCLUDEFILES=
INCLUDEPATH=
LIBFILE= test.a
XFLAGS= -c
MEMFLAGS=
physmath.o: physmath.h
libtest: lib $(OBJFILES) physmath.h
X $(CCX) -g -o libtest $(MEMFLAGS) pmtest.o $(LIBFILE) -lm
nolibtest: $(OBJFILES) physmath.h
X $(CCX) -g -o nolibtest $(MEMFLAGS) $(OBJFILES) -lm
lib: physmath.o
X ar ru $(LIBFILE) physmath.o
X ranlib $(LIBFILE)
X ar vt $(LIBFILE)
clean:
X rm -f *.o *.man *~ *# core *test
X.c.o:
X $(CCX) $(MEMFLAGS) $(FLAGS) $*.c
X.SUFFIXES: .o .c
X
END_OF_FILE
if test 491 -ne `wc -c <'Makefile'`; then
echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'README' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(152 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
To make an executable without the library:
X
X make libtest
X
To make an executable using the library:
X
X make nolibtest
X
pi should have the value 3.14...
X
END_OF_FILE
if test 152 -ne `wc -c <'README'`; then
echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'physmath.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'physmath.c'\"
else
echo shar: Extracting \"'physmath.c'\" \(242 characters\)
sed "s/^X//" >'physmath.c' <<'END_OF_FILE'
X// -*- C++ -*-
X#include "physmath.h"
X
X#include <stdlib.h>
X#include <math.h>
X
double pi;
physmath_dummy physmath_initialize;
X
X// dummy constructor to initialize constants
X
physmath_dummy::physmath_dummy()
X{
X
X pi = 4 * atan((double) 1.0);
X
X}
X
END_OF_FILE
if test 242 -ne `wc -c <'physmath.c'`; then
echo shar: \"'physmath.c'\" unpacked with wrong size!
fi
# end of 'physmath.c'
fi
if test -f 'physmath.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'physmath.h'\"
else
echo shar: Extracting \"'physmath.h'\" \(279 characters\)
sed "s/^X//" >'physmath.h' <<'END_OF_FILE'
X#ifndef PHYSMATHH
X#define PHYSMATHH
X
X// dummy class to force initialization of all math / physics constants
X
class physmath_dummy {
X
public:
X physmath_dummy();
X};
X
extern double pi;
X
X// call constructor to initialize constants
X
extern physmath_dummy physmath_initialize;
X
X#endif
END_OF_FILE
if test 279 -ne `wc -c <'physmath.h'`; then
echo shar: \"'physmath.h'\" unpacked with wrong size!
fi
# end of 'physmath.h'
fi
if test -f 'pmtest.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'pmtest.c'\"
else
echo shar: Extracting \"'pmtest.c'\" \(134 characters\)
sed "s/^X//" >'pmtest.c' <<'END_OF_FILE'
X// -*- C++ -*-
X
X#include <math.h>
X#include <stdio.h>
X
X#include "physmath.h"
X
main()
X{
X printf("pi test: %8.5f\n", pi);
X return 0;
X}
END_OF_FILE
if test 134 -ne `wc -c <'pmtest.c'`; then
echo shar: \"'pmtest.c'\" unpacked with wrong size!
fi
# end of 'pmtest.c'
fi
echo shar: End of archive 1 \(of 1\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have the archive.
rm -f ark[1-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0
Technical Details
Message-ID:
<9208191627.AA01759@poincare.phys.cmu.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!mips!sdd.hp.com!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!poincare.phys.cmu.edu!keisterShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.help,comp.lang.c++ Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!mips!sdd.hp.com!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!poincare.phys.cmu.edu!keister From: keister@poincare.phys.cmu.edu (Bradley D. Keister) Subject: static constructors and libraries Message-ID: <9208191627.AA01759@poincare.phys.cmu.edu> Sender: daemon@cis.ohio-state.edu Organization: Gatewayed from the GNU Project mailing list help-g++@prep.ai.mit.edu Date: Wed, 19 Aug 1992 08:27:48 GMT Lines: 212