This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Shared library bug


"Bogus User" <bogus_user@hotmail.com> writes:

> I'm running RedHat Linux 6.0 using the version of egcs that comes with it, 
> gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release).
> 
> The problem seems to be that if a variable is declared inside a shared 
> library, the constructor doesn't get called.  If you compile the following 
> files (should be 3 of them plus a makefile) and try to run it, it seg faults 
> inside the Standard Template Library code.  I've tried this with a newer and 
> older version of the STL and both give the same results.
> 
> If the code is compiled into a static library, then everything runs fine.

1. Shared library code must be compiled with -fPIC.

2. I think you used the wrong command to build the shared library.

The following Makefile works:

----------------- Makefile ---------------------------------------

CPP = g++ -g
LIB = libtest.so
TARGET = test

all: clean ${LIB} ${TARGET}

test: test.cpp
	${CPP} -o test test.cpp -L. -ltest

libtest.so: test1.o
	g++ -shared -Wl,-soname,libtest.so -o libtest.so test1.o

test1.o: test1.cpp
	${CPP} -fPIC -o test1.o -c test1.cpp

clean:
	rm -f ${TARGET} *.o *.a *.so

------------------------------------------------------------------

-- 
Peter Österlund          Email:     peter.osterlund@mailbox.swipnet.se
Sköndalsvägen 35                    f90-pos@nada.kth.se
S-128 66 Sköndal         Home page: http://home1.swipnet.se/~w-15919
Sweden                   Phone:     +46 8 942647


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]